{"version":3,"file":"WithFormPrefill.CDLLAibX.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,MAAM,EAAQ,EAAgB,MAAM,KAAK,EAAU,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,KAAK,CAAmB,EAAE,GAAG,EAAgB,SAAS,EAAE,OAAO,IAAM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