{"version":3,"file":"LocaleLink.BoTqXhLP.mjs","names":["useRef"],"sources":["https:/framerusercontent.com/modules/lxkyPfmnulZ4iM3NExng/KOSpK2CsS8oZ37eulv1A/LocaleLink.js"],"sourcesContent":["import React,{useEffect,useRef}from\"react\";// Rewrites absolute same-site links (www.meditron.ch or the current host) that\n// point at /products into locale-prefixed relative links, e.g.\n//   https://www.meditron.ch/products?category=radiology\n// becomes  /de/products?category=radiology  on the German site.\n// CMS link fields cannot store relative URLs with query strings, so the values\n// stay absolute in the CMS and this override fixes them up post-mount.\n// The href attribute itself is rewritten (so middle-click / copy-link share\n// the right URL), target=_blank is stripped so Framer's external-URL default\n// cannot force a new tab, and a capture-phase click handler navigates\n// explicitly for plain left clicks. Modified clicks fall through to the\n// rewritten href. Only /products paths are touched.\n// The root node can be replaced during hydration reconciliation, so the root\n// is re-resolved on every pass via the node's own class and the listeners sit\n// on document level.\nconst LOCALES=new Set([\"de\",\"fr\",\"it\"]);const SITE_HOST=\"www.meditron.ch\";const localePrefix=()=>{const first=window.location.pathname.split(\"/\").filter(Boolean)[0];return LOCALES.has(first)?\"/\"+first:\"\";};const rewriteAnchor=anchor=>{let url;try{url=new URL(anchor.getAttribute(\"href\")||\"\",window.location.href);}catch{return null;}if(url.host!==SITE_HOST&&url.host!==window.location.host)return null;const segments=url.pathname.split(\"/\").filter(Boolean);const path=LOCALES.has(segments[0])?segments.slice(1):segments;if(path.length!==1||path[0]!==\"products\")return null;const target=localePrefix()+\"/products\"+url.search+url.hash;if(anchor.getAttribute(\"href\")!==target)anchor.setAttribute(\"href\",target);anchor.removeAttribute(\"target\");const rel=(anchor.getAttribute(\"rel\")||\"\").split(/s+/).filter(t=>t&&t!==\"noopener\"&&t!==\"noreferrer\");if(rel.length)anchor.setAttribute(\"rel\",rel.join(\" \"));else anchor.removeAttribute(\"rel\");return target;};const rewriteAll=root=>{const anchors=root.tagName===\"A\"?[root]:Array.from(root.querySelectorAll(\"a\"));for(const a of anchors)rewriteAnchor(a);};export function withLocaleLink(Component){return function LocaleLink(props){const ref=useRef(null);useEffect(()=>{const cls=props.className||\"\";const getRoot=()=>{if(ref.current&&ref.current.isConnected)return ref.current;if(!cls)return null;return document.querySelector(\".\"+cls.trim().split(/s+/).join(\".\"));};const rewrite=()=>{const root=getRoot();if(root)rewriteAll(root);};rewrite();const observer=new MutationObserver(rewrite);observer.observe(document.body,{childList:true,subtree:true,attributes:true,attributeFilter:[\"href\"]});const onClick=e=>{if(e.defaultPrevented)return;if(e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;const target=e.target;const anchor=target&&target.closest?target.closest(\"a\"):null;if(!anchor)return;const root=getRoot();if(!root||!root.contains(anchor))return;const rewritten=rewriteAnchor(anchor);if(!rewritten)return;e.preventDefault();window.location.assign(rewritten);};document.addEventListener(\"click\",onClick,true);return()=>{observer.disconnect();document.removeEventListener(\"click\",onClick,true);};},[]);return /*#__PURE__*/React.createElement(Component,{...props,ref});};}\nexport const __FramerMetadata__ = {\"exports\":{\"withLocaleLink\":{\"type\":\"reactHoc\",\"name\":\"withLocaleLink\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./LocaleLink.map"],"mappings":"gIAcskC,SAAgB,EAAe,EAAU,CAAC,OAAO,SAAoB,EAAM,CAAC,IAAM,EAAIA,EAAO,IAAI,EAA08B,OAAx8B,MAAc,CAAC,IAAM,EAAI,EAAM,WAAW,GAAS,MAAgB,EAAI,SAAS,EAAI,QAAQ,YAAmB,EAAI,QAAY,EAAuB,SAAS,cAAc,IAAI,EAAI,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC,EAAvE,KAAiF,MAAY,CAAC,IAAM,EAAK,EAAQ,EAAK,GAAK,EAAW,CAAI,CAAE,EAAE,EAAQ,EAAE,IAAM,EAAS,IAAI,iBAAiB,CAAO,EAAE,EAAS,QAAQ,SAAS,KAAK,CAAC,UAA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