var __defProp=Object.defineProperty,__defNormalProp=(e,t,o)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,__publicField=(e,t,o)=>__defNormalProp(e,"symbol"!=typeof t?t+"":t,o);!function(){"use strict";class e extends HTMLElement{constructor(){super(),__publicField(this,"HOST","https://xapps-geo-ca956fdeab0c.herokuapp.com"),__publicField(this,"MAIN_CSS","native-geo-markets.min.css"),__publicField(this,"SHOW_RULES",{load:"everyload",cookie:"cookie",session:"session"}),__publicField(this,"VARS",{KEY:"ngr-markets-session",CLOSED_KEY:"ngr-markets-closed"}),this.template=this.querySelector("#NGR-Markets-Template"),this.stylesheet=document.querySelector(`[href*='${this.MAIN_CSS}']`),this.widgetIcon=this.dataset.widgetIcon,this.widgetStickyIcon=this.dataset.widgetStickyIcon,this.modal=null,this.customOpenerIconSrc=this.dataset.customOpenerIconSrc,this.testMode=!1,this.userLocale=this.dataset.lng||window.Shopify.locale,this.shopifyTemplate=this.dataset.shopifyTemplate,this.shopifytemplateDir=this.dataset.shopifyTemplateDir,this.flagSrc=this.dataset.flagSrc,this.marketCountries=null,this.userGeoData}async connectedCallback(){var e,t;if(this.checkTestMode(),this.clearLocalData(),!this.stylesheet)return void console.error("[NGR APP]: Stylesheet not found. Contact app support.");const o=await this.getData();if(!o||!o&&!o.status||!o.data)return void console.error("[NGR APP]: Store data not found. Contact app support.");const n=await this.getGeo();if(!n||!(null==n?void 0:n.country))return void console.error("[NGR APP]: GEO Location not detected. Contact app support.");this.userGeoData=n;const{markets:l,configs:i}=o.data;if(l){if(null==i?void 0:i.widget){if(this.topBarMoveTop(null==(e=null==i?void 0:i.basicConfigs)?void 0:e.type))return;const o=this.widget(l,i);if(!o)return void console.error("[NGR APP]: Widget not found. Contact app support.");const n=this.genCustomStyles(i),s=this.attachShadow({mode:"closed"});s.appendChild(this.stylesheet),n&&s.appendChild(n),s.appendChild(o),this.customOpenerIcon(),this.widgetEvents(s,null==(t=null==i?void 0:i.basicConfigs)?void 0:t.showFrequency),await this.widgetLogic(s,null==i?void 0:i.basicConfigs,l),this.displayWidget()}}else console.warn("[NGR APP]: Shopify Markets not configured.")}checkTestMode(){(window.location.search.includes("ngr-markets-test")||"#ngr-markets-test"===window.location.hash||"true"===this.dataset.testMode&&window.Shopify.designMode)&&(this.testMode=!0)}clearLocalData(){"#ngr-clear-user-data"===window.location.hash&&(this.deleteCookie(this.VARS.KEY),this.deleteCookie(this.VARS.CLOSED_KEY),sessionStorage.removeItem(this.VARS.KEY),sessionStorage.removeItem(this.VARS.CLOSED_KEY))}async getData(){var e;const t=null==(e=null==window?void 0:window.Shopify)?void 0:e.shop,o=`${this.HOST}/api/shop-markets?shop=${t}`;try{return await fetch(o).then(e=>e.json())}catch(n){console.log("Error",n)}}async getGeo(){var e,t,o,n,l;const i=this.getCookie(this.VARS.KEY);if(i&&!this.testMode)return JSON.parse(i);const s=null==window?void 0:window.ngr_countries_window,r=await fetch("/browsing_context_suggestions.json").then(e=>e.json());if(!s||!r)return console.error("[NGR APP]: User GEO location or countries list not detected. Contact app support please.");const a=null==(e=null==r?void 0:r.detected_values)?void 0:e.country.handle,d={country_name:(null==(o=null==(t=null==r?void 0:r.detected_values)?void 0:t.country)?void 0:o.name)||(null==(n=null==r?void 0:r.detected_values)?void 0:n.country_name),country:a,continent:null==(l=s[a])?void 0:l.continent};return this.setCookie(this.VARS.KEY,JSON.stringify(d),7),window[this.VARS.KEY]=d,d}topBarMoveTop(e){return"topbar"===e&&!this.hasAttribute("data-moved")&&(this.setAttribute("data-moved",""),document.body.insertBefore(this,document.body.firstChild),this.displayWidget(),!0)}widget(e,t){var o,n;if(!this.template||!e||!t)return;const{basicConfigs:l,advancedConfigs:i,plan:s}=t,r=null==(n=null==(o=this.template)?void 0:o.content)?void 0:n.cloneNode(!0),a=r.querySelector("[data-ngr-markets-modal]");return this.modal=a,2===s&&i&&""!==(null==i?void 0:i.html_id)&&a.setAttribute("id",null==i?void 0:i.html_id),this.builder(r,l,e,s)}genCustomStyles(e){if(!e)return;const{basicConfigs:t,advancedConfigs:o,plan:n}=e,l=document.createElement("style");let i="";if(t&&!(null==o?void 0:o.disable_basic_css)&&3!==n){const{modalBgColor:e,modalTextColor:o,modalBorderColor:n,buttonsBgColor:l,buttonsColor:s,font:r}=t;i+=`\n .ngr-markets-modal{\n ${r&&""!=r&&"inherit"!==r&&"undefined"!==r?"font-family:'"+r+"', sans-serif;":""}\n }\n .ngr-markets-modal__content{\n ${""!=e?"background-color:"+e+";":""}\n ${""!=o?"color:"+o+";":""}\n ${""!=n?"border-color:"+n+";":""}\n }\n ${""!=e&&".ngr-markets-modal__close{ background-color:"+e+" !important;}"}\n .ngr-markets-modal__form-content .select select{\n ${r&&""!=r&&"inherit"!==r&&"undefined"!==r?"font-family:'"+r+"', sans-serif;":""}\n }\n .ngr-markets-modal__button-main{\n ${""!=l?"background-color:"+l+";":""}\n ${""!=s?"border-color:"+s+";":""}\n ${""!=s?"color:"+s+";":""}\n ${""!=r?"font-family:'"+r+"', sans-serif;":""}\n }\n .ngr-markets-modal__button-main:hover{\n ${""!=s?"background-color:"+s+";":""}\n ${""!=l?"border-color:"+l+";":""}\n ${""!=l?"color:"+l+";":""}\n }\n `}return o&&""!==o.css&&2===n&&(i+=o.css),l.textContent=i.replace(/\n/g,"").replace(/ +/g,""),l}customOpenerIcon(){var e;const t=document.querySelectorAll("[href$='#ngr-markets-open']");if(this.customOpenerIconSrc&&""!==this.customOpenerIconSrc&&(null==t?void 0:t.length)){const o=this.builOpenerIconElement(this.customOpenerIconSrc);if(!o)return;for(let n=0;n{n.closeModal(l,t)});const s=l.querySelector("[data-ngr-markets-toggle]");s&&s.addEventListener("click",()=>{n.toggleModal(l,t)});const r=l.querySelector("[data-ngr-markets-button]");r&&r.addEventListener("click",e=>{var o,i,s,r;if(n.analytics(),(null==(o=l.querySelector("[name='country_code']"))?void 0:o.value)===(null==(i=null==window?void 0:window.Shopify)?void 0:i.country)&&(null==(s=l.querySelector("[name='language_code']"))?void 0:s.value)===(null==(r=null==window?void 0:window.Shopify)?void 0:r.locale))return e.preventDefault(),void n.closeModal(l,t);n.closeModal(l,t,!0),l.classList.add("loading"),setTimeout(()=>{l.classList.remove("loading")},5e3)}),document.addEventListener("click",e=>{if(e){(e.target.closest("[data-ngr-markets-open]")||e.target.closest("[href$='#ngr-markets-open']"))&&(e.preventDefault(),n.openModal())}})}async widgetLogic(e,t,o){var n,l,i,s,r;if(!t||!e)return console.error("[NGR APP]: Configs or shadowRoot list not found. Contact app support please.");const{showRules:a,showFrequency:d}=t;if(this.testMode)this.openModal();else if("manual"!==a){if("autoGeo"===a){const e=o.MarketRegionCountry.map(e=>e.code),t=this.getCookie(this.VARS.KEY);if(t&&!this.testMode){const n=JSON.parse(t);if(!e.includes(n.country))return;return void this.widgetBehaviour(d,n,o)}const a=await this.getCountriesJSON(),c=await fetch("/browsing_context_suggestions.json").then(e=>e.json());if(!a||!c)return console.error("[NGR APP]: User GEO location or countries list not detected. Contact app support please.");const u=null==(n=null==c?void 0:c.detected_values)?void 0:n.country.handle,h={country_name:(null==(i=null==(l=null==c?void 0:c.detected_values)?void 0:l.country)?void 0:i.name)||(null==(s=null==c?void 0:c.detected_values)?void 0:s.country_name),country:u,continent:null==(r=a[u])?void 0:r.continent};if(this.setCookie(this.VARS.KEY,JSON.stringify(h),7),window[this.VARS.KEY]=h,!e.includes(h.country))return;return void this.widgetBehaviour(d,h,o)}this.widgetBehaviour(d)}}widgetBehaviour(e=this.SHOW_RULES.session,t,o){var n,l,i,s,r,a,d,c,u,h,v;if(!(null==t?void 0:t.country)&&e===this.SHOW_RULES.load)return this.openModal();const g=e=>{if("CH"===(null==t?void 0:t.country)||!window.location.host.includes("got-bag.com"))if(e===this.SHOW_RULES.load)this.openModal();else{(e===this.SHOW_RULES.cookie?this.getCookie(this.VARS.CLOSED_KEY):sessionStorage.getItem(this.VARS.CLOSED_KEY))||this.openModal()}},m=null==t?void 0:t.country;if(m){const t=null==(n=null==window?void 0:window.Shopify)?void 0:n.country,p=null==(l=null==window?void 0:window.Shopify)?void 0:l.locale,f=m&&(null==(i=null==window?void 0:window.ngr_countries_window[m])?void 0:i.languages[0]),w=null==(r=null==(s=null==o?void 0:o.MarketRegionCountry)?void 0:s.find(e=>(null==e?void 0:e.code)===m))?void 0:r.__parentId,y=null==(d=null==(a=null==o?void 0:o.Market)?void 0:a.find(e=>(null==e?void 0:e.id)===w))?void 0:d.webPresence;let S=[];if(y){S=[(null==(c=null==y?void 0:y.defaultLocale)?void 0:c.locale)?null==(u=null==y?void 0:y.defaultLocale)?void 0:u.locale:null==y?void 0:y.defaultLocale,...((null==(h=null==y?void 0:y.alternateLocales)?void 0:h.find(e=>e.locale))?null==(v=null==y?void 0:y.alternateLocales)?void 0:v.filter(e=>null==e?void 0:e.published).map(e=>e.locale):null==y?void 0:y.alternateLocales)||[]]}const _=t&&m&&t!==m,k=p&&f&&f!==p&&(null==S?void 0:S.includes(f));(_||k)&&g(e)}else g(e)}builder(e,t,o,n){var l,i,s;const{title:r,title_locales:a,text:d,text_locales:c,buttonText:u,buttonText_locales:h,showFlag:v,showFrequency:g,topbarSticky:m,stickyOpener:p,stickyVerticalPosition:f,icon:w,iconWidth:y,stickyToggleIcon:S,type:_}=t,k=this.getUserData(),b=(null==k?void 0:k.country_name)||(null==(l=window.ngr_countries_window[null==k?void 0:k.country])?void 0:l.name),C=null==(i=window.ngr_countries_window[null==k?void 0:k.country])?void 0:i.name;let E=r,L=d,I=u;2===n&&(E=this.getTranslation(r,a),L=this.getTranslation(d,c),I=this.getTranslation(u,h)),b&&(L=L.replace(/\[\[country\]\]/g,b)),C&&(L=L.replace(/\[\[country_eng\]\]/g,C));const O=e.querySelector("[data-ngr-markets-close]"),M=this.buildStickyIconElement(S,p,null==k?void 0:k.country,null==(s=null==window?void 0:window.Shopify)?void 0:s.country),A=this.buildIconElement(w,y),R=this.buildTitleElement(E),T=this.buildTextElement(L,n),P=this.buildMarketsDropdowns(o,t),$=this.buildFlagElement(null==k?void 0:k.country),x=e.querySelector("[data-ngr-markets-button]"),D=e.querySelector("[data-ngr-markets-content]");return"topbar"===_&&(this.modal.classList.add("top-bar"),m&&(this.style.top=0,this.style.position="sticky",this.style.zIndex="999999999999"),P&&P.appendChild(x)),"sticky"===_&&(this.modal.classList.add("sticky-bar"),this.modal.style.top=f+"%",setTimeout(()=>{this.modal.classList.add("transition")},2500)),M&&"sticky"===_&&O&&(O.removeAttribute("data-ngr-markets-close"),O.setAttribute("data-ngr-markets-toggle",""),O.innerHTML="",O.appendChild(M)),A&&D.appendChild(A),R&&D.appendChild(R),T&&D.appendChild(T),$&&v&&D.appendChild($),P&&D.appendChild(P),x&&I&&(x.textContent=I),e}buildStickyIconElement(e,t,o,n){e="geo"===t&&o?this.flagSrc.replace(/\b([a-z]+)\.svg/,`${o.toLowerCase()}.svg`):"market"===t&&n?this.flagSrc.replace(/\b([a-z]+)\.svg/,`${n.toLowerCase()}.svg`):"default"===e?this.widgetStickyIcon:e;const l=document.createElement("img");return l.loading="lazy",l.alt="Geo location toggler",l.width=100,l.height=100,l.src=e,l}buildIconElement(e,t=100,o="Redirects Icon"){if(!e||""===e)return;const n=document.createElement("img");n.loading="lazy",n.alt=o,n.width=t,n.height=100,n.src="default"===e?this.widgetIcon:e;const l=document.createElement("div");return l.classList.add("ngr-markets-modal__icon"),l.appendChild(n),l}buildTitleElement(e){if(!e||""===e)return;const t=document.createElement("h2");return t.classList.add("ngr-markets-modal__title"),t.textContent=e,t}buildTextElement(e,t){if(!e||""===e||3===t||"


"===e||"


"===e)return;const o=document.createElement("div");return o.classList.add("ngr-markets-modal__text"),o.innerHTML=e,o}buildMarketsDropdowns(e,t){var o,n,l,i,s,r,a,d,c,u,h,v,g;if(!e||!e.MarketRegionCountry.length)return;const{dropdownDefault:m,showLngSelector:p,showCountrySelector:f}=t,{MarketRegionCountry:w,Market:y,MarketWebPresence:S,BackupRegion:_}=e;let k=null;const b=w.sort((e,t)=>e.name>t.name?1:-1),C=null==y?void 0:y.filter(e=>(null==e?void 0:e.enabled)||"ACTIVE"===(null==e?void 0:e.status)),E=null==C?void 0:C.map(e=>e.id),L=b.filter(e=>E.includes(e.__parentId)),I=(null==S?void 0:S.length)?null==(o=null==w?void 0:w.find(e=>e.id===(null==_?void 0:_.id)))?void 0:o.__parentId:null==(n=null==L?void 0:L.find(e=>e.primary))?void 0:n.__parentId,O=document.createElement("div");if(O.classList.add("ngr-markets-modal__form-content"),f){const e=document.createElement("div");e.classList.add("select"),e.classList.add("country-selector");const t=document.createElement("select");t.name="country_code";if(null==L||L.forEach(e=>{var o,n,l;const i=document.createElement("option"),s=null==(o=null==window?void 0:window.ngr_currencies_window[e.currency.currencyCode])?void 0:o.symbol_native,r=(null==(n=null==window?void 0:window.ngr_countries_window[e.code])?void 0:n.native)||"";i.textContent=r!==e.name?e.name+" / "+r+` (${e.currency.currencyCode} ${s})`:e.name+` (${e.currency.currencyCode} ${s})`,i.value=e.code,i.setAttribute("data-market",e.__parentId),t.appendChild(i),e.code===(null==(l=null==this?void 0:this.userGeoData)?void 0:l.country)&&(k=e.code)}),this.userGeoData&&"market"!==m&&k)t.value=k;else{const e=t.options,o=null==(l=null==window?void 0:window.Shopify)?void 0:l.country,n=Array.from(e).some(e=>e.value===o);t.value=n?o:e.length>0?e[0].value:0}e.appendChild(t),O.appendChild(e)}const M=[],A=O.querySelector(".country-selector select"),R=null==A?void 0:A.options[null==A?void 0:A.selectedIndex],T=(null==R?void 0:R.getAttribute("data-market"))||I;if(null==S?void 0:S.length){const e=S.find(e=>e.__parentId===T);if(e)null==(i=null==e?void 0:e.rootUrls)||i.forEach(e=>M.push({...e,marketId:T}));else{const e=null==(r=null==(s=S[0])?void 0:s.defaultLocale)?void 0:r.locale;null==(h=null==(u=null==(c=null==(d=null==(a=S[0])?void 0:a.defaultLocale)?void 0:d.marketWebPresences)?void 0:c.find(t=>{var o,n;return(null==(n=null==(o=null==t?void 0:t.domain)?void 0:o.localization)?void 0:n.defaultLocale)===e}))?void 0:u.rootUrls)||h.forEach(e=>M.push({...e,marketId:T}))}}else{const e=y.find(e=>!((null==e?void 0:e.id)!==T||!(null==e?void 0:e.webPresence))||(null==e?void 0:e.primary));null==(v=null==e?void 0:e.webPresence)||v.rootUrls.forEach(t=>M.push({...t,marketId:e.id}))}if(p){let e=[];const t=O.querySelector(".country-selector select"),o=document.createElement("div");o.classList.add("select");const n=document.createElement("select");n.name="language_code",null==M||M.forEach(t=>{var o,l;const i=this.createLngOption(t);i&&n.appendChild(i);const s=null==t?void 0:t.locale,r=null==(l=null==window?void 0:window.ngr_countries_window[null==(o=null==this?void 0:this.userGeoData)?void 0:o.country])?void 0:l.languages;s&&r.includes(s)&&"market"!==m&&e.push(s)});this.userGeoData&&"market"!==m?(null==e?void 0:e.length)?n.value=e[0]:n.selectedIndex=0:n.value=null==(g=null==window?void 0:window.Shopify)?void 0:g.locale,f&&t&&t.addEventListener("change",e=>{var t,o,l,i,s,r,a,d,c,u,h;const v=null==(o=null==e?void 0:e.target)?void 0:o.options[null==(t=null==e?void 0:e.target)?void 0:t.selectedIndex],g=(null==v?void 0:v.getAttribute("data-market"))||I;if(!g)return;n.options.length=0;const m=[];if(null==S?void 0:S.length){const e=S.find(e=>e.__parentId===g);if(e)null==(l=null==e?void 0:e.rootUrls)||l.forEach(e=>m.push({...e,marketId:g}));else{const e=null==(s=null==(i=S[0])?void 0:i.defaultLocale)?void 0:s.locale;null==(u=null==(c=null==(d=null==(a=null==(r=S[0])?void 0:r.defaultLocale)?void 0:a.marketWebPresences)?void 0:d.find(t=>{var o,n;return(null==(n=null==(o=null==t?void 0:t.domain)?void 0:o.localization)?void 0:n.defaultLocale)===e}))?void 0:c.rootUrls)||u.forEach(e=>m.push({...e,marketId:g}))}}else{const e=y.find(e=>e.id===g||e.primary);null==(h=null==e?void 0:e.webPresence)||h.rootUrls.forEach(t=>m.push({...t,marketId:e.id}))}(null==m?void 0:m.length)&&(null==m||m.forEach(e=>{const t=this.createLngOption(e);t&&n.appendChild(t),n.selectedIndex=0}))}),o.appendChild(n),O.appendChild(o)}return O}createLngOption(e){const t=document.createElement("option"),o=null==window?void 0:window.ngr_languages_window[e.locale],n=(null==o?void 0:o.name)!==(null==o?void 0:o.native)?(null==o?void 0:o.name)+" / "+(null==o?void 0:o.native):null==o?void 0:o.name;return t.textContent=n||e.locale,t.value=e.locale,t.setAttribute("data-market",e.marketId),t}buildFlagElement(e){if(!e||""===e||!this.flagSrc||""===this.flagSrc)return;const t=this.flagSrc.replace(/\b([a-z]+)\.svg/,`${e.toLowerCase()}.svg`),o=document.createElement("div");o.classList.add("ngr-markets-modal__flag");const n=document.createElement("img");return n.loading="lazy",n.alt=e,n.width=100,n.height=50,n.src=t,o.appendChild(n),o}builOpenerIconElement(e){if(e&&""!==e)return`geo location icon`}analytics(){var e;try{const t=null==(e=null==window?void 0:window.Shopify)?void 0:e.shop,o=`${this.HOST}/api/analytics/markets-button?shop=${t}`;return void fetch(o)}catch(t){console.log(t)}}getTranslation(e,t){return e&&(t&&t[this.userLocale]||e)||""}openModal(e){const t=e||this.modal;t&&t.setAttribute("data-open","")}closeModal(e,t,o){const n=e||this.modal;n&&(o||n.removeAttribute("data-open"),t&&t===this.SHOW_RULES.session?sessionStorage.setItem(this.VARS.CLOSED_KEY,1):t&&t===this.SHOW_RULES.cookie&&this.setCookie(this.VARS.CLOSED_KEY,1,7))}toggleModal(e,t){const o=e||this.modal;o&&(o.hasAttribute("data-open")?this.closeModal(e,t):this.openModal(e))}getUserData(){return JSON.parse(this.getCookie(this.VARS.KEY))||(null==window?void 0:window[this.VARS.KEY])}async getCountriesJSON(){const e=localStorage.getItem("ngr_countries");if(e)return JSON.parse(e);const t=`${this.HOST}/api/countries`;try{const e=await fetch(t).then(e=>e.json());return localStorage.setItem("ngr_countries",JSON.stringify({...e})),e}catch(o){return!1}}displayWidget(){this.style.display="initial"}setCookie(e,t,o){var n="";if(o){var l=new Date;l.setTime(l.getTime()+24*o*60*60*1e3),n="; expires="+l.toUTCString()}document.cookie=e+"="+(t||"")+n+"; path=/"}getCookie(e){for(var t=e+"=",o=document.cookie.split(";"),n=0;n