function ProductModel(t){this.ProductCode=t.ProductCode,this.ProductName=t.ProductName,this.ProductDiscount=t.ProductDiscount,this.ProductPrice=t.ProductPrice,this.ProductShip=t.ProductShip,this.Qty=t.Qty||1,this.images=t.images,this.videos=t.videos,this.Colour=this.extractColourFromName(this.ProductName),this.Size=this.extractDimensionFromName(this.ProductName),this.Frame=this.extractFrameFromName(this.ProductName)}function customtrackEvent(t,e){try{gtag("event",t,{event_category:"engagement",event_label:e,value:1}),window.dataLayer=window.dataLayer||[],window.dataLayer.push({event:t})}catch(t){console.log(t)}}ProductModel.prototype.extractColourFromName=function(t){for(var e=["Red","Blue","Green","Yellow","Black","White","Purple","Orange","Pink","Grey","Taupe","Leaftree","LeafTree"],o=0;o{try{if(t&&t.gazebo_details_fragmentHTML){const e=document.getElementById("gazebo_details_fragmentHTML");if(e){e.innerHTML=t.gazebo_details_fragmentHTML,observeAnimations();try{pjslider_init()}catch(t){}}else console.error('Element with ID "gazebo_details_fragmentHTML" not found.');const o=document.querySelector("h1");if(o&&(o.innerHTML=t.ProductName),t.featuredVideo){const e=document.getElementById("featuredVideo");if(e&&"IFRAME"===e.tagName){const o=`https://www.youtube.com/embed/${t.featuredVideo}`;e.src!==o&&(e.src=o)}else console.error('Element with ID "featuredVideo" not found or is not an iframe.')}t.meta&&(document.title=t.meta.title||document.title,document.querySelector('meta[name="description"]').content=t.meta.description||"",document.querySelector('meta[name="keywords"]').content=t.meta.keywords||"")}else console.error("Invalid data or gazebo_details_fragmentHTML not found.")}catch(t){}};var Gazebo,GazeboModel=function(){this.formattedProductShip=ko.observable(),this.Qty=ko.observable(1);var t=window.__builder.flagSKU||"10536";this.Artwork=ko.observableArray(),this.getShipping=function(){const t=Gazebo.getBuilderProducts(),{productShipping:e}=t;return parseInt(e)},this.Flag={Type:ko.observable(t),Product:ko.observable()},this.Base={Option:ko.observable(),Product:ko.observable()},this.calculateGazeboProducts=function(){try{const t=transformedData.find((t=>"Flags"==t.name)).products.find((t=>t.ProductCode===this.Flag.Type()));this.Flag.Product(t);const e=transformedData.find((t=>"Bases"==t.name)).products.find((t=>t.ProductCode===this.Base.Option()));e&&this.Base.Product(e)}catch(t){console.log(t)}},this.calcCosts=()=>{let t=0,e=0;return[this.Flag,this.Base].forEach((function(o){if(o.Product()&&o.Product().ProductPrice){var r=o.Product().ProductPrice,n=o.Product().Qty,a=o.Product().ProductDiscount,c=getFinalPrice(r,a)*n;t+=c,e+=r*n-c}})),e=Number(parseFloat(e).toFixed(2)),t*=this.Qty(),e*=this.Qty(),{totalCost:t,totalSaving:e}},this.calcBundleCosts=()=>{let t=0,e=0;return[this.Flag,this.Base].forEach((function(o){if(o.Product()&&o.Product().ProductPrice){var r=o.Product().ProductPrice,n=o.Product().Qty,a=o.Product().ProductDiscount,c=getFinalPrice(r,a)*n;t+=c,e+=r*n-c}})),e=Number(parseFloat(e).toFixed(2)),t*=this.Qty(),e*=this.Qty(),{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;return[this.Flag,this.Base].forEach((function(o){if(o.Product()&&o.Product().ProductPrice){let r={sku:o.Product().ProductCode,qty:o.Product().Qty};o==Gazebo.Canopy&&"Yes"==Gazebo.Printing.Option()&&(r.Artwork="Yes"),o.Product().ProductShip>e&&(e=o.Product().ProductShip),t.push(r)}})),{skusToAdd:t,productShipping:e}},this.click_addbuilderproducts_bundle=function(){const t=this.getBundleProducts();this.add(t)},this.getBreakDown=function(){let t=[];return[this.Flag,this.Base].forEach((function(e){e.Product()&&e.Product().ProductPrice&&e.Product().Qty>0&&t.push(e.Product())})),t},this.getBuilderProducts=()=>{const t=[];var e=1;return[this.Flag,this.Base].forEach((function(o){if(o.Product()&&o.Product().ProductPrice){let r={sku:o.Product().ProductCode,qty:o.Product().Qty*Gazebo.Qty()};o==Gazebo.Canopy&&"Yes"==Gazebo.Printing.Option()&&(r.Artwork="Yes"),o.Product().ProductShip>e&&(e=o.Product().ProductShip),t.push(r)}})),{skusToAdd:t,productShipping:e}},this.click_addbuilderproducts=function(){const t=this.getBuilderProducts();this.add(t)},this.add=t=>{const{skusToAdd:e,productShipping:o}=t;o>1&&modalOpen(document.getElementById("help-oos")),fetch("/basket/add-multiple",{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}),t.mysteryGifts?showOverlay({URL:"/popups/mystery-gift"}):showAlert("icon-ok-circled",CONST_PRODUCT_ADD_TITLE,CONST_PRODUCT_ADDED+" "+CONST_PRODUCT_ADDED_APPEND,"#FFFFFF",!1)})).catch((t=>{console.error("Error:",t)}))},this.Flag.Type.subscribe((function(t){Gazebo.calculateGazeboProducts(),Gazebo.updateTabs()})),this.Flag.Product.subscribe((function(t){t&&t.images&&setTimeout((function(){var e=[],o=t.images;for(var r in o)e.push(new galleryModel(o[r]));var n=t.videos;for(var r in n)e.push(new galleryModel(n[r]));gallery=e,"undefined"!=typeof createGallery&&createGallery()}),0)})),this.Base.Option.subscribe((function(t){Gazebo.calculateGazeboProducts()})),this.updateTabs=function(){Gazebo.Flag.Product()&&fetch("/printing/printed-flags/fragment?code="+Gazebo.Flag.Product().ProductCode).then((t=>{if(!t.ok)throw new Error("Network response was not ok "+t.statusText);return t.json()})).then((t=>{Gazebo.formattedProductShip(t.formattedProductShip),setGazeboDetailsFragmentHTML(t),updateUrlAndReload(t.URL)})).catch((t=>{console.error("Fetch error:",t)}))}};function updateUrlAndReload(t){try{t.startsWith("/")&&(t=t.substring(1));const e=window.location.origin,o=new URL(t,e),r=e+o.pathname+o.search;window.history.pushState({path:r},"",r);document.querySelector('link[rel="canonical"]').href=r;const n=document.querySelector(".breadcrumb .current-page");if(n){const t=o.pathname.split("/").filter((t=>t.length>0)),e=t[t.length-1]||"",r=decodeURIComponent(e.replace(/-/g," "));n.textContent=r}else console.warn(".breadcrumb .current-page element not found.")}catch(t){console.error("Error updating URL:",t)}}function updateFlagType(){const t=document.getElementById("flag-select").value;Gazebo.Flag.Type(t)}document.addEventListener("DOMContentLoaded",(function(){(Gazebo=new GazeboModel).calculateGazeboProducts(),setTimeout((function(){Gazebo.updateTabs()}),0);try{ko.applyBindings(Gazebo)}catch(t){}document.querySelectorAll(".hiddenUntilKO").forEach((function(t){t.classList.remove("hiddenUntilKO")}))})),window.addEventListener("popstate",(function(t){window.location.reload(!1)}));const builderUploadArtwork=()=>{const t=document.querySelector('input[name="multfile"]'),e=Gazebo.Flag.Product().ProductCode,o=t.files[0];if(!o)return void showAlert("icon-alert","Error!","Please select a file to upload!","#FFFFFF",!1);showAlert("fa-pulse icon-spin5","Uploading","Please wait...","#FFFFFF",!0);const r=new FormData;r.append("multfile",o),r.append("ProductCode",e),fetch("/session/artwork",{method:"PUT",body:r}).then((t=>t.json())).then((t=>{console.log("Success:",t),document.body.classList.remove("noexit"),showAlert("icon-ok-circled","Files uploaded successfully","","#FFFFFF",!1)})).catch((t=>{console.error("Error:",t),document.body.classList.remove("noexit"),showAlert("icon-alert","Files upload error",t,"#FFFFFF",!1)}))};function deletePhoto(t){if(confirm("Delete artwork "+t)){const e="/session/artwork/"+encodeURIComponent(t);fetch(e,{method:"DELETE"}).then((t=>{if(!t.ok)throw new Error("Network response was not ok.");return t.json()})).then((t=>{showAlert("icon-trash","Deleted!","","#FFFFFF",!1),setTimeout(pollUploadedImages,1e3),setTimeout(pollUploadedImages,3e3),setTimeout(pollUploadedImages,5e3)})).catch((t=>{console.error("Error:",t)}))}}function pollUploadedImages(){fetch("/session/artworkGroupByProduct").then((t=>t.json())).then((t=>{const e=t.map(((t,e)=>({...t,Id:e+1})));Gazebo.Artwork(e)})).catch((t=>{console.error("Error:",t)}))}document.addEventListener("DOMContentLoaded",(function(){pollUploadedImages(),setInterval(pollUploadedImages,15e3)}));const deleteArtworkBtn=t=>{deletePhoto(t.getAttribute("data-art-name"))};function transformInputToProductModels(){var t=[];return window.__input.forEach((function(e){var o={};o.name=e.name,o.products=e.data.map((function(t){return new ProductModel(t)})),t.push(o)})),t}var transformedData=transformInputToProductModels();