class l{constructor(t){this.productPanelHtml=this.getProductPanelHtml(t)}getProductPanelHtml(t){t.product=this.normalizeAttributes(t.product);let e=_.template($("#flash-sale-product-template").html());return $(e(t))}normalizeAttributes(t){return $.isEmptyObject(t)?{id:null,pivot:{campaign_end:null,price:{amount:null},qty:null}}:$.isEmptyObject(FleetCart.errors["flash_sale.products"])?t:{id:t.id,name:t.name,pivot:{campaign_end:t.campaign_end,price:{amount:t.price},qty:t.qty}}}render(){return this.attachEventListeners(),window.admin.dateTimePicker(this.productPanelHtml.find(".datetime-picker")),this.productPanelHtml}attachEventListeners(){this.productPanelHtml.find(".delete-product-panel").on("click",()=>{this.productPanelHtml.remove()})}}class n{constructor(){this.productCount=0,this.addFlashSaleProducts(FleetCart.data["flash_sale.products"]),this.productCount===0&&this.addProduct(),this.addFlashSaleProductsError(FleetCart.errors["flash_sale.products"]),this.attachEventListeners(),this.makeProductPanelsSortable()}addFlashSaleProducts(t){for(let e of t)this.addProduct(e)}addProduct(t={}){let e=new l({productPanelNumber:this.productCount++,product:t});$("#products-wrapper").append(e.render()),window.admin.selectize()}addFlashSaleProductsError(t){for(let e in t){let r=this.getInputFieldForKey(e).parent();r.addClass("has-error"),r.append(`<span class="help-block">${t[e][0]}</span>`)}}getInputFieldForKey(t){let e=t.split(".");return e=e.map(r=>r.split("_").join("-")),$(`#${e.join("-")}`)}attachEventListeners(){$(".add-product").on("click",()=>{this.addProduct()})}makeProductPanelsSortable(){Sortable.create(document.getElementById("products-wrapper"),{handle:".drag-handle",animation:150})}}new n;window.admin.removeSubmitButtonOffsetOn(["#products"]);
