{"version":3,"file":"KeepLinkParameters.bbfa5gVN.mjs","names":["useState","Children"],"sources":["https:/framerusercontent.com/modules/tPOX56UVmZz15iEL5eqm/W9fVUY1rOFOTYdWTc8rV/KeepLinkParameters.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useState,useEffect,Children,cloneElement,isValidElement}from\"react\";function isRemakeitLink(value){return typeof value===\"string\"&&value.startsWith(\"https://app.remakeit.io\");}function hasHrefProp(props){return props.hasOwnProperty(\"href\")&&isRemakeitLink(props.href);}function hasButtonLinkProp(props){return props.hasOwnProperty(\"buttonLink\")&&isRemakeitLink(props.buttonLink);}function modifyUrl(url,search){let modifiedUrl;if(url.includes(\"?lang=fr\")){modifiedUrl=`${url.replace(\"?lang=fr\",\"\")}${search}&lang=fr`;}else if(url.includes(\"?lang=en\")){modifiedUrl=`${url.replace(\"?lang=en\",\"\")}${search}&lang=en`;}else{modifiedUrl=`${url}${search}`;}if(modifiedUrl.includes(\"&lang=en\")&&!modifiedUrl.includes(\"?\")){modifiedUrl=modifiedUrl.replace(\"&lang=en\",\"?lang=en\");}if(modifiedUrl.includes(\"&lang=fr\")&&!modifiedUrl.includes(\"?\")){modifiedUrl=modifiedUrl.replace(\"&lang=fr\",\"?lang=fr\");}return modifiedUrl;}function buildLinkUpdates(props,search){const updates={};if(hasHrefProp(props)){updates.href=modifyUrl(props.href,search);}if(hasButtonLinkProp(props)){updates.buttonLink=modifyUrl(props.buttonLink,search);}return updates;}export function withKeepLinkParameters(Component){return props=>{// Initialize state to hold the search string\nconst[search,setSearch]=useState(\"\");// Update the search string after the component mounts\nuseEffect(()=>{setSearch(window.location.search);},[]);// If the top-level props have an href or buttonLink, modify them directly\nconst topLevelUpdates=buildLinkUpdates(props,search);if(Object.keys(topLevelUpdates).length>0){return /*#__PURE__*/_jsx(Component,{...props,...topLevelUpdates});}// If there are children, modify the first link found among them\nif(props.children){const modifiedChildren=modifyFirstHrefChild(props.children,search);return /*#__PURE__*/_jsx(Component,{...props,children:modifiedChildren});}// If no href/buttonLink or children, render the component as is\nreturn /*#__PURE__*/_jsx(Component,{...props});};}function modifyFirstHrefChild(element,search){let found=false;function traverse(node){if(found){return node;}if(/*#__PURE__*/isValidElement(node)){const{props}=node;const updates=buildLinkUpdates(props,search);if(Object.keys(updates).length>0){found=true;return /*#__PURE__*/cloneElement(node,updates);}const children=props.children;if(children){const newChildren=Children.map(children,(child,index)=>{const newChild=traverse(child);if(/*#__PURE__*/isValidElement(newChild)&&newChild.key==null){return /*#__PURE__*/cloneElement(newChild,{key:index});}return newChild;});return /*#__PURE__*/cloneElement(node,{children:newChildren});}return node;}// Handle non-element nodes (strings, numbers, etc.)\nif(typeof node===\"string\"||typeof node===\"number\"||node==null){return node;}// If node is a function or other non-renderable type, skip it\nreturn null;}return traverse(element);}\nexport const __FramerMetadata__ = {\"exports\":{\"withKeepLinkParameters\":{\"type\":\"reactHoc\",\"name\":\"withKeepLinkParameters\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./KeepLinkParameters.map"],"mappings":"4JAAsH,SAAS,EAAe,EAAM,CAAC,OAAO,OAAO,GAAQ,UAAU,EAAM,WAAW,0BAA0B,CAAE,SAAS,EAAY,EAAM,CAAC,OAAO,EAAM,eAAe,OAAO,EAAE,EAAe,EAAM,KAAK,CAAE,SAAS,EAAkB,EAAM,CAAC,OAAO,EAAM,eAAe,aAAa,EAAE,EAAe,EAAM,WAAW,CAAE,SAAS,EAAU,EAAI,EAAO,CAAC,IAAI,EAA6d,MAAjd,CAAgM,EAA7L,EAAI,SAAS,WAAW,CAAc,GAAG,EAAI,QAAQ,WAAW,GAAG,GAAG,EAAO,UAAmB,EAAI,SAAS,WAAW,CAAc,GAAG,EAAI,QAAQ,WAAW,GAAG,GAAG,EAAO,UAA4B,GAAG,IAAM,IAAa,EAAY,SAAS,WAAW,EAAE,CAAC,EAAY,SAAS,IAAI,GAAE,EAAY,EAAY,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