function ProductModel(t){this.ProductCode=t.ProductCode,this.ProductName=t.ProductName,this.ProductDiscount=t.ProductDiscount,this.ProductPrice=t.ProductPrice,this.Qty=t.Qty||1,this.images=t.images,this.Material=this.extractMaterialFromName(this.ProductName),this.Size=this.extractDimensionFromName(this.ProductName)}function transformInputToProductModels(){var t=[];return window.__input.forEach((function(e){var r={};r.name=e.name,r.products=e.data.map((function(t){return new ProductModel(t)})),t.push(r)})),t}ProductModel.prototype.extractMaterialFromName=function(t){for(var e=["PE","PVC"],r=0;r"Groundbars"==t.name)).products.find((t=>-1!==t.ProductName.indexOf(Marquee.Frame.Size())))},buyitwith:ko.observable(!0),buyitwithToggle:function(){setTimeout((function(){Marquee.Groundbars.buyitwith(!Marquee.Groundbars.buyitwith())}),0)}},this.Anchors={Empty:new ProductModel({ProductCode:"None",ProductName:"None"}),Option:ko.observable(),Product:ko.observable(),Options:ko.observableArray(),toggle:function(){setTimeout((function(){Marquee.Anchors.Option(Marquee.Anchors.Option()===Marquee.Anchors.Empty?Marquee.Anchors.tiedownkit():Marquee.Anchors.Empty)}),0)},generateOptions:function(){var t=function(t,e){var r=new ProductModel(t=transformedData.find((t=>"Anchorage"==t.name)).products.find((e=>e.ProductCode==t)));return e>1&&(r.Qty=e,r.ProductName="(x"+r.Qty+") "+r.ProductName+" +"+localizeCost(r.ProductPrice*r.Qty)),r},e=[];e.push(this.Empty);const r=extractDimensions(Marquee.Frame.Size());r?6==r.width?e.push(t("01003",r.height)):4==r.width?12==r.height?e.push(t("01003",8)):10==r.height?e.push(t("01003",6)):8==r.height||6==r.height?e.push(t("01003",4)):e.push(t("01003",3)):3==r.width&&(12==r.height?e.push(t("01003",8)):10==r.height?e.push(t("01003",5)):8==r.height?e.push(t("01003",4)):6==r.height?e.push(t("01003",3)):e.push(t("01003",2))):e.push(t("01003",2)),this.Options(e)},previewOption:function(){return transformedData.find((t=>"Anchorage"==t.name)).products.find((t=>"01003"===t.ProductCode))}},this.Extras={Option:ko.observable()},this.Heaters={Product:ko.observable(),Qty:ko.observable(0),qty_increase:function(){qty_increase(Marquee.Heaters.Qty)},qty_decrease:function(){qty_decrease(Marquee.Heaters.Qty)},generateOptions:function(){var t=transformedData.find((t=>"Heaters"==t.name)).products[0];t.Qty=0,this.Product(t)}},this.Lighting={Product:ko.observable(),Qty:ko.observable(0),qty_increase:function(){qty_increase(Marquee.Lighting.Qty)},qty_decrease:function(){qty_decrease(Marquee.Lighting.Qty)},generateOptions:function(){var t=transformedData.find((t=>"Lighting"==t.name)).products[0];t.Qty=0,this.Product(t)}},this.Lining={Option:ko.observable(),Product:ko.observable(),toggle:function(){setTimeout((function(){Marquee.Lining.Option("None"===Marquee.Lining.Option()?"Yes":"None")}),0)},previewOption:function(){return transformedData.find((t=>"Lining"==t.name)).products.find((t=>-1!==t.ProductName.indexOf(Marquee.Frame.Size())))}},this.calculateMarquee=function(){var t=transformedData.find((t=>"Marquees"==t.name)).products.find((t=>(t.Material||"").toUpperCase()==this.Canopy.Material()&&(t.Size||"")==this.Frame.Size()));this.Canopy.Product(t)},this.calculateMarqueeProducts=function(){try{if("Yes"==this.Groundbars.Option()?this.Groundbars.Product(Marquee.Groundbars.previewOption()):this.Groundbars.Product(void 0),"Yes"==this.Lining.Option()){var t=transformedData.find((t=>"Lining"==t.name)).products.find((t=>-1!==t.ProductName.indexOf(this.Frame.Size())));t?this.Lining.Product(t):(showAlert("icon-cancel-circled","Error","Lining option not available for this size!","#FFFFFF",!1),this.Lining.Option("None"))}else this.Lining.Product(void 0)}catch(t){console.log(t)}},this.calcCosts=()=>{let t=0,e=0;return[this.Frame,this.Canopy,this.Groundbars,this.Anchors,this.Heaters,this.Lighting,this.Lining].forEach((function(r){if(r.Product()&&r.Product().ProductPrice){var o=r.Product().ProductPrice,i=r.Product().Qty,n=r.Product().ProductDiscount,a=getFinalPrice(o,n)*i;t+=a,e+=o*i-a}})),e=Number(parseFloat(e).toFixed(2)),{totalCost:t,totalSaving:e}},this.calcBundleCosts=()=>{let t=0,e=0;[this.Frame,this.Canopy].forEach((function(r){if(r.Product()&&r.Product().ProductPrice){var o=r.Product().ProductPrice,i=r.Product().Qty,n=r.Product().ProductDiscount,a=getFinalPrice(o,n)*i;t+=a,e+=o*i-a}}));return[this.Groundbars].forEach((function(r){if(r.buyitwith()&&r.previewOption()&&r.previewOption().ProductPrice){var o=r.previewOption().ProductPrice,i=r.previewOption().Qty,n=r.previewOption().ProductDiscount,a=getFinalPrice(o,n)*i;t+=a,e+=o*i-a}})),e=Number(parseFloat(e).toFixed(2)),{totalCost:t,totalSaving:e}},this.calculateGazeboCost=function(){const{totalCost:t}=this.calcCosts();return t},this.getSaving=function(){const{totalSaving:t}=this.calcCosts();return t},this.getBundleProducts=()=>{const t=[];var e=1;[this.Frame,this.Canopy].forEach((function(r){if(r.Product()&&r.Product().ProductPrice){let o={sku:r.Product().ProductCode,qty:r.Product().Qty};r.Product().ProductShip>e&&(e=r.Product().ProductShip),o.qty>0&&t.push(o)}}));return[this.Groundbars].forEach((function(r){if(r.buyitwith()&&r.previewOption()&&r.previewOption().ProductPrice){let o={sku:r.previewOption().ProductCode,qty:r.previewOption().Qty};r.previewOption().ProductShip>e&&(e=r.previewOption().ProductShip),o.qty>0&&t.push(o)}})),{skusToAdd:t,productShipping:e}},this.click_addbuilderproducts_bundle=function(){const t=this.getBundleProducts();this.add(t)},this.getBuilderProducts=function(){const t=[];var e=1;return[this.Frame,this.Canopy,this.Groundbars,this.Anchors,this.Heaters,this.Lighting,this.Lining].forEach((function(r){if(r.Product()&&r.Product().ProductPrice){let o={sku:r.Product().ProductCode,qty:r.Product().Qty};r.Product().ProductShip>e&&(e=r.Product().ProductShip),o.qty>0&&t.push(o)}})),{skusToAdd:t,productShipping:e}},this.click_addbuilderproducts=function(){const t=this.getBuilderProducts();this.add(t)},this.add=t=>{const{skusToAdd:e,productShipping:r}=t;r>1&&modalOpen(document.getElementById("help-oos")),fetch(`${window.location.pathname}/add`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:e})}).then((t=>t.json())).then((t=>{setBasket({Qty:t.totalQty,Cost:t.totalPrice}),showAlert("icon-ok-circled",CONST_PRODUCT_ADD_TITLE,CONST_PRODUCT_ADDED+" "+CONST_PRODUCT_ADDED_APPEND,"#FFFFFF",!1)})).catch((t=>{console.error("Error:",t)}))},this.click_includeall=function(){Marquee.Groundbars.Option("Yes"),showAlert("icon-ok-circled",CONST_PRODUCT_INCLUDE_ALL_TITLE,CONST_PRODUCT_INCLUDE_ALL_MSG,"#FFFFFF",!1)},this.displaySnippet=function(){try{switch(this.Canopy.Material()){case"PE":return"Low cost and functional";case"PVC":return"Commercial Quality Marquee";default:return""}}catch(t){return""}},this.Frame.Size.subscribe((function(t){Marquee.calculateMarquee(),Marquee.calculateMarqueeProducts(),Marquee.Anchors.generateOptions(),updateUrlAndReload("material="+Marquee.Canopy.Material().toLowerCase()+"&size="+Marquee.Frame.Size())})),this.Canopy.Material.subscribe((function(t){Marquee.calculateMarquee(),updateUrlAndReload("material="+Marquee.Canopy.Material().toLowerCase()+"&size="+Marquee.Frame.Size())})),this.Canopy.Product.subscribe((function(t){t&&t.images&&setTimeout((function(){var e=[],r=t.images;for(var o in r)e.push(new galleryModel(r[o]));gallery=e,"undefined"!=typeof createGallery&&createGallery()}),0),fetch("/gala-tent-marquee/fragment?code="+Marquee.Canopy.Product().ProductCode).then((t=>{if(!t.ok)throw new Error("Network response was not ok "+t.statusText);return t.json()})).then((t=>{document.querySelector("#marquee-builder-description").innerHTML=t.ProductDesc,document.querySelector(".specs").innerHTML=t.ProductSpec})).catch((t=>{console.error("Fetch error:",t)}))})),this.Groundbars.Option.subscribe((function(t){Marquee.calculateMarqueeProducts()})),this.Anchors.Option.subscribe((function(t){Marquee.Anchors.Product(t),Marquee.calculateMarqueeProducts()})),this.Heaters.Qty.subscribe((function(t){Marquee.Heaters.Product({...Marquee.Heaters.Product(),Qty:t})})),this.Lighting.Qty.subscribe((function(t){Marquee.Lighting.Product({...Marquee.Lighting.Product(),Qty:t})})),this.Lining.Option.subscribe((function(t){Marquee.calculateMarqueeProducts()}))};function qty_increase(t){var e=t();e=isNaN(e)?0:e,t(qty_check(++e))}function qty_decrease(t){var e=t();e=isNaN(e)?0:e,t(qty_check(--e))}function qty_check(t){var e=isNaN(t)?0:t;return e>999?e=999:e<0&&(e=0),e}function extractDimensions(t){const e=t.match(/(\d+)m\s*x\s*(\d+)m/);if(e&&e.length>=3){return{width:parseInt(e[1],10),height:parseInt(e[2],10)}}return null}function updateUrlAndReload(t){let e=window.location.href.split("?")[0]+"?"+t;window.history.pushState({path:e},"",e)}document.addEventListener("DOMContentLoaded",(function(){(Marquee=new MarqueeModel).calculateMarquee(),Marquee.Anchors.generateOptions(),Marquee.Heaters.generateOptions(),Marquee.Lighting.generateOptions(),ko.applyBindings(Marquee,document.getElementById("content"))})),window.addEventListener("popstate",(function(t){window.location.reload(!1)}));