{"version":3,"file":"WithFormPrefill.BHMmpXFb.mjs","names":[],"sources":["https:/framerusercontent.com/modules/JTCnTVWgGBAOdwPs8Gi5/Fkyl18SeRoIJX5q5YaEz/WithFormPrefill.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect}from\"react\";/**\n * withFormPrefill\n *\n * Reads URL search params and writes their values into the matching hidden\n * FramerForms inputs by name attribute. Works around FramerForms' \"Hidden\"\n * toggle silently disabling the built-in URL Parameter pre-fill on hidden\n * inputs.\n *\n * Also keeps the hidden fields in sync with the visible\n * \"preferowana-lokalizacja\" input: if the user edits that field to a value\n * different from the URL's `lokalizacja` parameter, the hidden date / time /\n * day fields are cleared (because they describe the originally-clicked\n * termin's CMS row and would now be misleading). If the user reverts to the\n * original location value, the hidden fields are restored.\n *\n * Attach to any element on /zapisy/{slug}. The override scans the whole\n * document, so the attach point doesn't matter.\n */// URL param name -> HTML input name attribute in FramerForms.\nconst PARAM_TO_INPUT_NAME={date_from:\"data-od\",date_to:\"data-do\",days:\"dni\",time_from:\"czas-od\",time_to:\"czas-do\"};const LOKALIZACJA_INPUT_NAME=\"preferowana-lokalizacja\";export function withFormPrefill(Component){return props=>{useEffect(()=>{const allParams=new URLSearchParams(window.location.search);const originalEntries=Array.from(allParams.entries()).filter(([k])=>k in PARAM_TO_INPUT_NAME);if(originalEntries.length===0)return;const urlLokalizacja=allParams.get(\"lokalizacja\")||\"\";// Targets is the desired value for each hidden input. We flip\n// between the original URL values and empty strings depending\n// on whether the visible location field still matches the URL.\nconst buildTargets=clear=>{const m=new Map;originalEntries.forEach(([key,value])=>{m.set(PARAM_TO_INPUT_NAME[key],clear?\"\":value);});return m;};let targets=buildTargets(false);// Native setter for controlled React inputs.\nconst nativeSetter=Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,\"value\")?.set;const setInputValue=(input,value)=>{if(input.value===value)return;if(nativeSetter)nativeSetter.call(input,value);else input.value=value;if(value===\"\")input.removeAttribute(\"value\");else input.setAttribute(\"value\",value);input.dispatchEvent(new Event(\"input\",{bubbles:true}));input.dispatchEvent(new Event(\"change\",{bubbles:true}));};const apply=()=>{targets.forEach((value,inputName)=>{const inputs=document.querySelectorAll(`input[name=\"${inputName}\"]`);inputs.forEach(input=>setInputValue(input,value));});};// Watch the visible location input. When its value diverges from\n// the URL's lokalizacja param, clear the hidden termin fields.\n// When it matches again, restore them.\nconst onLocationInput=e=>{const target=e.target;if(!target||target.name!==LOKALIZACJA_INPUT_NAME)return;const shouldClear=(target.value||\"\")!==urlLokalizacja;targets=buildTargets(shouldClear);apply();};document.addEventListener(\"input\",onLocationInput,true);// Initial pass + staggered retries for first-step inputs.\napply();const timers=[setTimeout(apply,100),setTimeout(apply,500),setTimeout(apply,1500),setTimeout(apply,3e3)];// Permanent observer for multi-step forms (later steps mount on\n// demand).\nconst observer=new MutationObserver(apply);observer.observe(document.body,{childList:true,subtree:true});// Slow poll as a safety net.\nconst interval=setInterval(apply,1e3);// Last-chance enforcement right before submission.\nconst onSubmitCapture=()=>apply();document.addEventListener(\"submit\",onSubmitCapture,true);return()=>{timers.forEach(clearTimeout);clearInterval(interval);observer.disconnect();document.removeEventListener(\"input\",onLocationInput,true);document.removeEventListener(\"submit\",onSubmitCapture,true);};},[]);return /*#__PURE__*/_jsx(Component,{...props});};}\nexport const __FramerMetadata__ = {\"exports\":{\"withFormPrefill\":{\"type\":\"reactHoc\",\"name\":\"withFormPrefill\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./WithFormPrefill.map"],"mappings":"gIAkB0K,SAAgB,EAAgB,EAAU,CAAC,MAAO,KAAQ,MAAc,CAAC,IAAM,EAAU,IAAI,gBAAgB,EAAO,SAAS,OAAO,CAAO,EAAgB,MAAM,KAAK,EAAU,SAAS,CAAC,CAAC,QAAQ,CAAC,KAAK,KAAK,EAAoB,CAAC,GAAG,EAAgB,SAAS,EAAE,OAAO,IAAM,EAAe,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