{"version":3,"file":"CountryPopup.C7f1rait.mjs","names":["useState"],"sources":["https:/framerusercontent.com/modules/oETlOD5gb78BzTn0JlBv/JcZic0WWvb1WNl8XQIRN/CountryPopup.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useState,useEffect}from\"react\";import{addPropertyControls,ControlType}from\"framer\";const LOCALIZATION_QUERY=`\n  query {\n    localization {\n      availableCountries {\n        isoCode\n        name\n        currency {\n          isoCode\n          symbol\n        }\n      }\n    }\n  }\n`;// Corrected: Maps exact URL subpaths (keys) to Shopify Country ISO codes (values)\nconst LOCALE_MAPPING={fr:\"FR\",de:\"DE\",da:\"DK\",es:\"ES\",it:\"IT\",nl:\"NL\",pl:\"PL\",ro:\"RO\",sv:\"SE\",cs:\"CZ\"};// Standardized display names to override Shopify's default names if needed\nconst COUNTRY_DISPLAY_NAMES={FR:\"France\",DE:\"Germany\",DK:\"Denmark\",ES:\"Spain\",IT:\"Italy\",NL:\"Netherlands\",PL:\"Poland\",RO:\"Romania\",SE:\"Sweden\",CZ:\"Czechia\"};export default function MarketSelector(props){const{shopifyDomain,storefrontToken,triggerText,bgImage,mainBgColor,accentColor,fontMain,headingFont}=props;const[countries,setCountries]=useState([]);const[selectedCountry,setSelectedCountry]=useState(null);const[loading,setLoading]=useState(true);const[isVisible,setIsVisible]=useState(false);const[isMinimized,setIsMinimized]=useState(true);useEffect(()=>{const init=async()=>{if(!shopifyDomain||!storefrontToken)return;try{const res=await fetch(`https://${shopifyDomain}/api/2024-01/graphql.json`,{method:\"POST\",headers:{\"Content-Type\":\"application/json\",\"X-Shopify-Storefront-Access-Token\":storefrontToken},body:JSON.stringify({query:LOCALIZATION_QUERY})});const json=await res.json();const availableCountries=json?.data?.localization?.availableCountries;if(availableCountries&&availableCountries.length>0){const allowedIsos=Object.values(LOCALE_MAPPING);const filteredCountries=availableCountries.filter(c=>allowedIsos.includes(c.isoCode));setCountries(filteredCountries);// 1. Determine target locale from the URL\nconst pathSegments=typeof window!==\"undefined\"?window.location.pathname.split(\"/\").filter(Boolean):[];const firstSegment=pathSegments[0]?.toLowerCase();// Match against the corrected keys (e.g., 'da', 'sv', 'cs')\nconst isKnownLocale=Object.keys(LOCALE_MAPPING).includes(firstSegment);const currentUrlLocale=isKnownLocale?firstSegment:\"fr\";const defaultIsoForUrl=LOCALE_MAPPING[currentUrlLocale];// 2. Check local storage for saved preferences\nconst savedIso=localStorage.getItem(\"shopify_market_country\");const lastUrlLocale=localStorage.getItem(\"shopify_last_url_locale\");let finalIso;// 3. Logic: If the URL language changed, or no data is saved, force URL's default.\nif(currentUrlLocale!==lastUrlLocale||!savedIso){finalIso=defaultIsoForUrl;localStorage.setItem(\"shopify_last_url_locale\",currentUrlLocale);}else{finalIso=savedIso;}const initialCountry=filteredCountries.find(c=>c.isoCode===finalIso)||filteredCountries.find(c=>c.isoCode===\"FR\");setSelectedCountry(initialCountry);// 4. Force sync with local storage immediately\nif(initialCountry){localStorage.setItem(\"shopify_market_country\",initialCountry.isoCode);window.dispatchEvent(new Event(\"storage\"));window.dispatchEvent(new CustomEvent(\"marketCurrencyChanged\",{detail:initialCountry.isoCode}));}}}catch(error){}finally{setLoading(false);}};init();},[shopifyDomain,storefrontToken]);useEffect(()=>{const handleScroll=()=>{if(isVisible)return;const scrollable=document.documentElement.scrollHeight-window.innerHeight;if(scrollable<=0)return;const scrollPercent=window.scrollY/scrollable;if(scrollPercent>=.2){setIsVisible(true);}};window.addEventListener(\"scroll\",handleScroll);handleScroll();return()=>window.removeEventListener(\"scroll\",handleScroll);},[isVisible]);const handleMarketChange=e=>{const isoCode=e.target.value;const country=countries.find(c=>c.isoCode===isoCode);if(!country)return;setSelectedCountry(country);// Save the manual selection\nlocalStorage.setItem(\"shopify_market_country\",country.isoCode);window.dispatchEvent(new Event(\"storage\"));window.dispatchEvent(new CustomEvent(\"marketCurrencyChanged\",{detail:country.isoCode}));setIsMinimized(true);};if(loading||countries.length===0)return null;return /*#__PURE__*/_jsx(\"div\",{style:{position:\"fixed\",bottom:isVisible?\"24px\":\"-400px\",right:\"24px\",zIndex:99999,transition:\"bottom 0.5s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.5s ease\",opacity:isVisible?1:0,pointerEvents:isVisible?\"auto\":\"none\",display:\"flex\",flexDirection:\"column\",alignItems:\"flex-end\"},children:isMinimized?/*#__PURE__*/_jsx(\"div\",{onClick:()=>setIsMinimized(false),style:{width:\"56px\",height:\"56px\",backgroundColor:mainBgColor,borderRadius:\"16px\",border:\"1px solid rgba(255,255,255,0.18)\",boxShadow:\"0 12px 28px rgba(0,0,0,0.7)\",display:\"flex\",alignItems:\"center\",justifyContent:\"center\",cursor:\"pointer\",color:\"#fff\",fontFamily:headingFont,fontSize:\"15px\",fontWeight:\"700\",transition:\"transform 0.2s ease, border-color 0.2s ease\",userSelect:\"none\"},onMouseEnter:e=>{e.currentTarget.style.transform=\"scale(1.06)\";e.currentTarget.style.borderColor=accentColor;},onMouseLeave:e=>{e.currentTarget.style.transform=\"scale(1)\";e.currentTarget.style.borderColor=\"rgba(255,255,255,0.18)\";},children:selectedCountry?.currency?.isoCode||\"EUR\"}):/*#__PURE__*/_jsxs(\"div\",{style:{width:\"320px\",backgroundColor:mainBgColor,borderRadius:\"16px\",border:\"1px solid rgba(255,255,255,0.1)\",overflow:\"hidden\",boxShadow:\"0 24px 48px rgba(0,0,0,0.8)\",position:\"relative\"},children:[/*#__PURE__*/_jsx(\"div\",{onClick:()=>setIsMinimized(true),style:{position:\"absolute\",top:\"12px\",right:\"12px\",width:\"28px\",height:\"28px\",backgroundColor:\"rgba(0,0,0,0.5)\",borderRadius:\"50%\",display:\"flex\",alignItems:\"center\",justifyContent:\"center\",cursor:\"pointer\",zIndex:10,color:\"#fff\",border:\"1px solid rgba(255,255,255,0.2)\",transition:\"background-color 0.2s ease\"},onMouseEnter:e=>e.currentTarget.style.backgroundColor=\"rgba(0,0,0,0.8)\",onMouseLeave:e=>e.currentTarget.style.backgroundColor=\"rgba(0,0,0,0.5)\",children:/*#__PURE__*/_jsx(\"svg\",{width:\"14\",height:\"14\",viewBox:\"0 0 24 24\",fill:\"none\",stroke:\"currentColor\",strokeWidth:\"2.5\",strokeLinecap:\"round\",strokeLinejoin:\"round\",children:/*#__PURE__*/_jsx(\"polyline\",{points:\"6 9 12 15 18 9\"})})}),/*#__PURE__*/_jsx(\"div\",{style:{height:\"120px\",backgroundImage:`linear-gradient(to bottom, rgba(0,0,0,0.1), ${mainBgColor}), url(${bgImage})`,backgroundSize:\"cover\",backgroundPosition:\"center\",display:\"flex\",alignItems:\"flex-end\",padding:\"24px\"},children:/*#__PURE__*/_jsx(\"h3\",{style:{fontFamily:headingFont,fontSize:\"22px\",color:\"#fff\",margin:0,textTransform:\"uppercase\",letterSpacing:\"0.02em\"},children:triggerText})}),/*#__PURE__*/_jsx(\"div\",{style:{padding:\"20px 24px 24px\"},children:/*#__PURE__*/_jsxs(\"div\",{style:{position:\"relative\"},children:[/*#__PURE__*/_jsx(\"select\",{value:selectedCountry?.isoCode||\"\",onChange:handleMarketChange,style:{width:\"100%\",backgroundColor:\"rgba(255,255,255,0.05)\",color:\"#fff\",border:\"1px solid rgba(255,255,255,0.1)\",padding:\"16px\",borderRadius:\"8px\",fontFamily:fontMain,fontSize:\"14px\",appearance:\"none\",cursor:\"pointer\",outline:\"none\",boxShadow:\"inset 0 2px 4px rgba(0,0,0,0.2)\"},children:countries.map(country=>/*#__PURE__*/_jsxs(\"option\",{value:country.isoCode,style:{background:mainBgColor,color:\"#fff\"},children:[COUNTRY_DISPLAY_NAMES[country.isoCode]||country.name,\" \",\"(\",country.currency.isoCode,\")\"]},country.isoCode))}),/*#__PURE__*/_jsx(\"svg\",{width:\"16\",height:\"16\",viewBox:\"0 0 24 24\",fill:\"none\",stroke:accentColor,strokeWidth:\"2\",style:{position:\"absolute\",right:\"16px\",top:\"50%\",transform:\"translateY(-50%)\",pointerEvents:\"none\"},children:/*#__PURE__*/_jsx(\"polyline\",{points:\"6 9 12 15 18 9\"})})]})})]})});}addPropertyControls(MarketSelector,{shopifyDomain:{type:ControlType.String,title:\"Shopify Domain\",defaultValue:\"your-store.myshopify.com\"},storefrontToken:{type:ControlType.String,title:\"Store Token\",defaultValue:\"Paste token here\"},triggerText:{type:ControlType.String,title:\"Header Text\",defaultValue:\"Select your currency\"},bgImage:{type:ControlType.Image,title:\"Header Image\"},mainBgColor:{type:ControlType.Color,title:\"Modal BG\",defaultValue:\"#0A0A0C\"},accentColor:{type:ControlType.Color,title:\"Accent Color\",defaultValue:\"#ff3b2e\"},fontMain:{type:ControlType.String,title:\"Body Font\",defaultValue:`\"Inter\", sans-serif`},headingFont:{type:ControlType.String,title:\"Heading Font\",defaultValue:`\"Anton\", sans-serif`}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"MarketSelector\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./CountryPopup.map"],"mappings":"sMAe6J,SAAwB,EAAe,EAAM,CAAC,GAAK,CAAC,gBAAc,kBAAgB,cAAY,UAAQ,cAAY,cAAY,WAAS,eAAa,EAAW,CAAC,EAAU,GAAcA,EAAS,CAAC,CAAC,EAAO,CAAC,EAAgB,GAAoBA,EAAS,IAAI,EAAO,CAAC,EAAQ,GAAYA,EAAS,EAAI,EAAO,CAAC,EAAU,GAAcA,EAAS,EAAK,EAAO,CAAC,EAAY,GAAgBA,EAAS,EAAI,EAM3R,OAN6R,MAAc,EAKhS,SALqT,CAAI,MAAC,GAAe,CAAC,GAAuB,GAAG,CAAwQ,IAAM,GAAmB,MAApC,MAA5O,MAAM,WAAW,EAAc,2BAA2B,CAAC,OAAO,OAAO,QAAQ,CAAC,eAAe,mBAAmB,oCAAoC,CAAe,EAAE,KAAK,KAAK,UAAU,CAAC,MAAM,CAAkB,CAAC,CAAC,CAAC,EAAA,CAAuB,KAAK,EAAA,EAAiC,MA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