{"version":3,"file":"withLocalizedPrice.BI-FJ923.mjs","names":["forwardRef","useRef","useState","useCallback","useMemo","__esmMin","navigator","pe","te","init_npm_react_18_3_1","window","ce","ne","J","init_jsx_runtime","_e","de","init_ssg_sandbox_shims","addPropertyControls","ControlType","init_framer_DxfB3JJo","getCurrencyFromCountryCode","region","countryCode","euroRegions","usdRegions","getCurrencyFromLocale","rawLocales","locale","currency","part","withLocalizedPrice","rest","props","elementRef","resolvedCurrency","setResolvedCurrency","setRefs","node","ref","localizedPrice","safeGbpPrice","gbpPrice","basePrice","eurPrice","usdPrice","cadPrice","audPrice","isCancelled","detectedCurrency","ipapiResponse","ipwhoisResponse","root","tokenCandidates","walker","currentNode","textNode","currentText","nextText","token","Component","init_withLocalizedPrice"],"sources":["https:/framerusercontent.com/modules/WjRtJ0PbIVSTcKozp3dp/Ti6fqILaHt1KlC0qvg7O/withLocalizedPrice.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{addPropertyControls,ControlType}from\"framer\";import{forwardRef,startTransition,useCallback,useEffect,useMemo,useRef,useState}from\"react\";const euroRegions=new Set([\"AT\",\"BE\",\"CY\",\"DE\",\"EE\",\"ES\",\"FI\",\"FR\",\"GR\",\"HR\",\"IE\",\"IT\",\"LT\",\"LU\",\"LV\",\"MT\",\"NL\",\"PT\",\"SI\",\"SK\"]);const usdRegions=new Set([\"AS\",\"EC\",\"FM\",\"GU\",\"MH\",\"MP\",\"PA\",\"PR\",\"PW\",\"SV\",\"TC\",\"TL\",\"UM\",\"US\",\"VG\",\"VI\",\"ZW\"]);function getCurrencyFromCountryCode(countryCode){const region=countryCode?.toUpperCase()??\"\";if(!region)return null;if(region===\"CA\")return\"CAD\";if(region===\"AU\")return\"AUD\";if(region===\"GB\")return\"GBP\";if(euroRegions.has(region))return\"EUR\";if(usdRegions.has(region))return\"USD\";return null;}function getCurrencyFromLocale(){if(typeof window===\"undefined\"||typeof navigator===\"undefined\"){return\"GBP\";}const rawLocales=Array.isArray(navigator.languages)&&navigator.languages.length>0?navigator.languages:[navigator.language];for(const locale of rawLocales){if(!locale||typeof locale!==\"string\")continue;const parts=locale.split(\"-\");const regionCode=parts.find(part=>/^[A-Za-z]{2}$/.test(part)&&part.length===2)?.toUpperCase()??\"\";const currency=getCurrencyFromCountryCode(regionCode);if(currency)return currency;}return\"GBP\";}export function withLocalizedPrice(Component){const Wrapped=/*#__PURE__*/forwardRef(function WithLocalizedPrice(props,ref){const{basePrice=\"\\xa3125\",gbpPrice=\"\\xa3125\",eurPrice=\"€149\",usdPrice=\"$165\",cadPrice=\"C$230\",audPrice=\"A$250\",...rest}=props;const elementRef=useRef(null);const[resolvedCurrency,setResolvedCurrency]=useState(\"GBP\");const setRefs=useCallback(node=>{elementRef.current=node;if(typeof ref===\"function\"){ref(node);}else if(ref&&typeof ref===\"object\"){ref.current=node;}},[ref]);const localizedPrice=useMemo(()=>{const safeGbpPrice=gbpPrice||basePrice;if(resolvedCurrency===\"EUR\")return eurPrice||safeGbpPrice;if(resolvedCurrency===\"USD\")return usdPrice||safeGbpPrice;if(resolvedCurrency===\"CAD\")return cadPrice||safeGbpPrice;if(resolvedCurrency===\"AUD\")return audPrice||safeGbpPrice;return safeGbpPrice;},[audPrice,basePrice,cadPrice,eurPrice,gbpPrice,resolvedCurrency,usdPrice]);useEffect(()=>{if(typeof window===\"undefined\"||typeof fetch===\"undefined\")return;let isCancelled=false;const resolveCurrency=async()=>{let detectedCurrency=null;try{const ipapiResponse=await fetch(\"https://ipapi.co/json/\");if(ipapiResponse.ok){const ipapiData=await ipapiResponse.json();detectedCurrency=getCurrencyFromCountryCode(ipapiData?.country_code);}}catch{}if(!detectedCurrency){try{const ipwhoisResponse=await fetch(\"https://ipwho.is/\");if(ipwhoisResponse.ok){const ipwhoisData=await ipwhoisResponse.json();detectedCurrency=getCurrencyFromCountryCode(ipwhoisData?.country_code);}}catch{}}if(!detectedCurrency)detectedCurrency=getCurrencyFromLocale();if(!isCancelled){startTransition(()=>{setResolvedCurrency(detectedCurrency??\"GBP\");});}};resolveCurrency();return()=>{isCancelled=true;};},[]);useEffect(()=>{if(typeof window===\"undefined\"||typeof document===\"undefined\")return;const root=elementRef.current;if(!root||!basePrice||!localizedPrice)return;const tokenCandidates=Array.from(new Set([basePrice,gbpPrice,eurPrice,usdPrice,cadPrice,audPrice].filter(Boolean)));const walker=document.createTreeWalker(root,NodeFilter.SHOW_TEXT);let currentNode=walker.nextNode();while(currentNode){const textNode=currentNode;const currentText=textNode.nodeValue??\"\";let nextText=currentText;for(const token of tokenCandidates){if(token&&nextText.includes(token)){nextText=nextText.split(token).join(localizedPrice);}}if(nextText!==currentText){textNode.nodeValue=nextText;}currentNode=walker.nextNode();}},[audPrice,basePrice,cadPrice,eurPrice,gbpPrice,localizedPrice,usdPrice]);return /*#__PURE__*/_jsx(Component,{ref:setRefs,...rest});});return Wrapped;}addPropertyControls(withLocalizedPrice,{basePrice:{type:ControlType.String,title:\"Base Price\",defaultValue:\"\\xa3125\"},gbpPrice:{type:ControlType.String,title:\"GBP Price\",defaultValue:\"\\xa3125\"},eurPrice:{type:ControlType.String,title:\"EUR Price\",defaultValue:\"€149\"},usdPrice:{type:ControlType.String,title:\"USD Price\",defaultValue:\"$165\"},cadPrice:{type:ControlType.String,title:\"CAD Price\",defaultValue:\"C$230\"},audPrice:{type:ControlType.String,title:\"AUD Price\",defaultValue:\"A$250\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"withLocalizedPrice\":{\"type\":\"reactHoc\",\"name\":\"withLocalizedPrice\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./withLocalizedPrice.map"],"mappings":"A,yOAA6a,SAASqB,EAA2B,EAAY,CAAC,IAAMC,EAAOC,GAAa,YAAY,GAAG,GAA8L,OAAvLD,EAAsBA,IAAS,KAAW,MAASA,IAAS,KAAW,MAASA,IAAS,KAAW,MAASE,EAAY,IAAIF,CAAM,EAAQ,MAASG,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