"use strict";window.EComPopup=function(){let e=async(...e)=>{if("admin.shopify.com"===window.location.host)return;let[t,s,o,i]=e;if(!("caches"in window)||window.Shopify&&window.Shopify.designMode||document.querySelector("#admin-bar-iframe"))return fetch(t,s).then(e=>e);let l=i?`${t}?v=${i}`:t;return caches.open(o).then(e=>e.match(l).then(o=>{if(o){let i=new Date(o.headers.get("date"));if(Date.now()(t.status<400&&e.put(l,t.clone()),t))}).catch(e=>{throw console.error(" Error in fetch handler:",e.message),e}))},t=[],s=!1,o=null,i=document.querySelector("#ecom-popup-data"),l=document.querySelector("#ecom-popup-variables");if(!i||!l){console.warn("Ecom popup data element not found");return}let n=JSON.parse(i.innerHTML),c=JSON.parse(l.innerHTML);if(n&&c){var r;let{page_type:a,page_title:p,country:d,language:u}=c,m=(r=[...n],r.sort((e,t)=>{let s=e.settings?.popup_priority||0,o=t.settings?.popup_priority||0;return s!==o?s-o:0}));m.forEach(e=>{if(e.settings?.status!=="public")return;let t=e.settings?.show_on,s=e.settings?.popup_event_show,o=e.settings?.custom_show_on??[],i=!0,l=!0,n=!0,c=!0;if("custom"===t&&"click"!==s){if(o&&o.includes(a)){let r="specific_"+a+"s",m=[];e.settings[r]&&e.settings[r].forEach(e=>{m.push(e.name)});let f=m.length>0?m:["all"];f.includes(p)||f.includes("all")||(i=!1)}else i=!1}if(!e.settings?.all_user){let g=e.settings?.specific_user;if(g){let y=null;"undefined"!=typeof ShopifyAnalytics&&ShopifyAnalytics.meta?.page?.customerId&&(y=ShopifyAnalytics.meta.page.customerId),g.includes("customer")?y||(l=!1):y&&(l=!1)}}if(!e.settings?.all_lang){let v=e.settings?.specific_lang??["all"];v.includes("all")||v.includes(u)||(n=!1)}if(!e.settings?.all_country){let L=e.settings?.specific_country??["all"];L.includes("all")||L.includes(d)||(c=!1)}let b="";"undefined"!=typeof EComposer&&EComposer.proxy_path&&(b=`${EComposer.proxy_path}/preview/`);if(b===window.location.pathname){let k=window.location.search,w=e.settings?.handle??e.settings?.slug??e.id;if(k.includes(w)){let E=document.querySelector(".ecom-popups-container");if(E){E.showModal();return}h(e,"preview")}}else if(!0===i&&!0===l&&!0===n&&!0===c){let S=e.id+"+"+e.settings?.popup_version;if("time_delay"===s){if(!$(S)){let x=e.settings?.time_delay??.5;setTimeout(()=>h(e),x=1e3*parseInt(x))}}else if("scroll"===s&&!$(S)){let _=parseFloat(e.settings?.scroll_distance??10),q=!1,T=()=>{let t=document.documentElement,s=t.scrollHeight-window.innerHeight,o=window.scrollY||t.scrollTop||0;!q&&o>=Math.max(0,_/100*s)&&(h(e),q=!0,window.removeEventListener("scroll",T))};window.addEventListener("scroll",T,{passive:!0}),T()}}})}function h(e,s=""){t.push({popupItem:e,preview:s}),f()}function f(){if(s||0===t.length)return;let{popupItem:e,preview:i}=t.shift();s=!0,o=e,y(e,i)}function g(){s=!1,o=null,setTimeout(()=>{f()},100)}async function y(t,s=""){try{if("admin.shopify.com"===window.location.host)return;let o=t.settings.handle??t.settings.slug,i=t.settings?.popup_version,l=window.location.origin+"?section_id=ecom-"+o+"-popup";window.location.href.includes("customer_posted=true")&&(l+="&customer_posted=true'");let n=await e(l,{method:"GET",headers:{"Content-Type":"text/html"}},"ecom-popup-cache-"+t.id,i);if(200===n.status){let c=await n.text();c&&function e(t,s,o){let i=document.createElement("div"),l="ecom-popup-container-template-html-"+s.id;i.classList.add(l),document.body.appendChild(i);let n=document.querySelector("."+l);s.settings?.devices&&Array.isArray(s.settings?.devices)&&(s.settings?.devices.includes("mobile")&&n.classList.add("ecom-popup-mobile-only"),s.settings?.devices.includes("tablet")&&n.classList.add("ecom-popup-tablet-only"),s.settings?.devices.includes("desktop")&&n.classList.add("ecom-popup-desktop-only"),["desktop","tablet","mobile"].forEach(e=>{s.settings?.devices.includes(e)||n.classList.add(`ecom-popup-hide-${e}`)})),n.innerHTML=t,requestAnimationFrame(()=>{n.classList.add("loaded")});let c=new CustomEvent("ecom:popupContainer:init",{detail:{wrapper:n}});document.dispatchEvent(c);let r=document.querySelector("."+l+" .ecom-popups-container");if(r&&(r.showModal(),document.body.classList.add("ecom-lock-scroll"),v(n,r),window.addEventListener("resize",()=>{v(n,r)}),"preview"!==o)){let a=s.id+"+"+s.settings?.popup_version,p=3600*parseInt(s.settings?.time_cookie_expires??0);r.addEventListener("click",function(e){e.target===r&&(r.close(),n.remove(),document.body.classList.remove("ecom-lock-scroll"),["time_delay","scroll"].includes(s.settings?.popup_event_show)&&L(a,l,{maxAgeSeconds:p,path:"/",sameSite:"Lax"}),g())}),r.addEventListener("keydown",function(e){"Escape"===e.key&&(r.close(),n.remove(),document.body.classList.remove("ecom-lock-scroll"),["time_delay","scroll"].includes(s.settings?.popup_event_show)&&L(a,l,{maxAgeSeconds:p,path:"/",sameSite:"Lax"}),g())});let d=r.querySelector(".ecom-popup-close-button");d&&d.addEventListener("click",()=>{r.close(),n.remove(),document.body.classList.remove("ecom-lock-scroll"),["time_delay","scroll"].includes(s.settings?.popup_event_show)&&L(a,l,{maxAgeSeconds:p,path:"/",sameSite:"Lax"}),g()});let u=r.querySelector(".ecom-close-not-show");u&&u.addEventListener("click",()=>{r.close(),n.remove(),document.body.classList.remove("ecom-lock-scroll"),L(a,l,{maxAgeSeconds:p=9999999999,path:"/",sameSite:"Lax"}),g()})}}(c,t,s)}else g()}catch(r){console.error("Error fetching popup content:",r),g()}}function v(e,t){let s=window.innerWidth;s<768?e.classList.contains("ecom-popup-hide-mobile")&&(t.close(),document.body.classList.remove("ecom-lock-scroll")):s<1025?e.classList.contains("ecom-popup-hide-tablet")&&(t.close(),document.body.classList.remove("ecom-lock-scroll")):e.classList.contains("ecom-popup-hide-desktop")&&(t.close(),document.body.classList.remove("ecom-lock-scroll"))}function $(e){let t=document.cookie.split("; ").find(t=>t.startsWith(e+"="));return t?decodeURIComponent(t.split("=")[1]):null}function L(e,t,{maxAgeSeconds:s,path:o="/",sameSite:i="Lax",secure:l=!1,domain:n}={}){let c=`${e}=${encodeURIComponent(t)}`;"number"==typeof s&&(c+=`; max-age=${s}`),o&&(c+=`; path=${o}`),i&&(c+=`; samesite=${i}`),l&&(c+="; secure"),n&&(c+=`; domain=${n}`),document.cookie=c}return{addToQueue:h,getCurrentPopup:()=>o,getQueue:()=>t,closeCurrentPopup:g,popupContainerHandler:y}}();