{"version":3,"file":"FormPrefill.BsgWiPkZ.mjs","names":["useRef"],"sources":["https:/framerusercontent.com/modules/Vl9senjr48WwfaZveKt0/qE7tXvfSxz9AanPyPTxw/FormPrefill.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useRef}from\"react\";import{addPropertyControls,ControlType}from\"framer\";// React controls input values internally — a plain `input.value =` assignment is\n// overwritten on the next render. Using the native HTMLInputElement setter bypasses\n// React's value tracking so the subsequent synthetic events are treated as real user\n// input, causing React to update its internal state and keep the value.\nfunction setField(form,name,value){if(!name||!value)return;// Traverse by property rather than CSS selector to avoid SyntaxError on\n// field names that contain quotes, brackets, or other selector metacharacters.\nconst input=Array.from(form.querySelectorAll(\"input\")).find(candidate=>candidate.name===name);if(!input){console.error(`[FormPrefill] input[name=\"${name}\"] not found in form`);return;}console.log(`[FormPrefill] filling input[name=\"${name}\"]`);const nativeSetter=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,\"value\")?.set;if(nativeSetter){nativeSetter.call(input,value);}else{input.value=value;}input.dispatchEvent(new Event(\"input\",{bubbles:true}));input.dispatchEvent(new Event(\"change\",{bubbles:true}));}export default function FormPrefill({apiBaseUrl=\"https://www.podium.com\",firstNameField=\"FirstName\",lastNameField=\"LastName\",emailField=\"Email\",phoneField=\"Phone\",companyField=\"Company\"}){const anchorRef=useRef(null);const prefillDataRef=useRef(null);useEffect(()=>{if(typeof window===\"undefined\")return;const cid=new URLSearchParams(window.location.search).get(\"cid\");if(!cid){console.log(\"[FormPrefill] no cid in URL, skipping prefill\");return;}const form=anchorRef.current?.closest(\"form\");if(!form){console.error(\"[FormPrefill] parent <form> not found — place FormPrefill inside a Framer Form component\");return;}const allInputs=Array.from(form.querySelectorAll(\"input\"));console.log(\"[FormPrefill] found inputs in form:\",allInputs.map(i=>`input[name=\"${i.name}\"]`));const fillAll=data=>{setField(form,firstNameField,data.firstName);setField(form,lastNameField,data.lastName);setField(form,emailField,data.email);setField(form,phoneField,data.phone);setField(form,companyField,data.companyName);};// Re-fill on submit (capture phase) to guard against React re-renders\n// clearing prefilled values before the form data is collected.\nconst handleSubmit=()=>{try{if(prefillDataRef.current)fillAll(prefillDataRef.current);}catch{// Never block form submission\n}};form.addEventListener(\"submit\",handleSubmit,true);const controller=new AbortController;let timerId;fetch(`${apiBaseUrl}/api/contact-prefill?cid=${encodeURIComponent(cid)}`,{signal:controller.signal}).then(res=>{if(!res.ok){console.error(`[FormPrefill] API returned ${res.status}`);return null;}return res.json();}).then(data=>{if(!data)return;console.log(\"[FormPrefill] prefill data received\");prefillDataRef.current=data;timerId=setTimeout(()=>fillAll(data),0);}).catch(err=>{if(err?.name!==\"AbortError\"){console.error(\"[FormPrefill] fetch failed:\",err);}});return()=>{controller.abort();clearTimeout(timerId);form.removeEventListener(\"submit\",handleSubmit,true);};},[apiBaseUrl,firstNameField,lastNameField,emailField,phoneField,companyField]);return /*#__PURE__*/_jsx(\"span\",{ref:anchorRef,style:{display:\"none\"}});}FormPrefill.displayName=\"FormPrefill\";addPropertyControls(FormPrefill,{apiBaseUrl:{type:ControlType.String,title:\"API Base URL\",defaultValue:\"https://www.podium.com\",description:\"Base URL of the vanbrunt API\"},firstNameField:{type:ControlType.String,title:\"First Name Field\",defaultValue:\"FirstName\",description:\"input[name] to fill with first name\"},lastNameField:{type:ControlType.String,title:\"Last Name Field\",defaultValue:\"LastName\",description:\"input[name] to fill with last name\"},emailField:{type:ControlType.String,title:\"Email Field\",defaultValue:\"Email\",description:\"input[name] to fill with email\"},phoneField:{type:ControlType.String,title:\"Phone Field\",defaultValue:\"Phone\",description:\"input[name] to fill with phone\"},companyField:{type:ControlType.String,title:\"Company Field\",defaultValue:\"Company\",description:\"input[name] to fill with company name\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"FormPrefill\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMapp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