{"version":3,"file":"PrefillFormInputs.DK1ROmXE.mjs","names":["useRef"],"sources":["https:/framerusercontent.com/modules/h5OT7hT5cvyqIK5epwmZ/LQhc3VFBfLTbYsfaAenO/PrefillFormInputs.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";import{useInstanceId,HiddenComponentLabel}from\"https://framerusercontent.com/modules/DwWOdDzQZGCuvkNlbUjZ/Rj7Kdx4qq62ukVsnw7Hz/FramerFormsShared.js\";import{useEffect,useRef}from\"react\";/**\n * @framerSupportedLayoutWidth any\n * @framerSupportedLayoutHeight\n * @framerDisableUnlink\n */export default function PrefillFormInputs(props){const{inputs}=props;const isCanvas=RenderTarget.current()===RenderTarget.canvas;const id=useInstanceId();const ref=useRef(null);useEffect(()=>{// Skip prefilling if we're in canvas mode or no inputs\nif(isCanvas||!Array.isArray(inputs)||inputs.length===0){return;}const timer=setTimeout(()=>{const urlSearchParams=new URLSearchParams(window.location.search);const urlParams={};// // Testing code\n// urlParams[\"slider\"] = 23\n// urlParams[\"country\"] = \"Brazil\"\n// urlParams[\"text\"] = \"Super duper text input\"\n// urlParams[\"imageSelect\"] = \"purple\"\n// urlParams[\"rating\"] = 3\nfor(const[key,value]of urlSearchParams.entries()){urlParams[key]=value;}// Find the closest parent form element\nconst form=ref.current?.closest(\"form\");for(let i=0;i<inputs.length;i++){const input=inputs[i];if(!input.inputName||!input.urlParameter){continue;}const value=urlParams[input.urlParameter];if(value){const query=`\n\t\t\t\t\t\tinput[name=\"${input.inputName}\"]:not([data-framerforms-no-prefill]),\n\t\t\t\t\t\tselect[name=\"${input.inputName}\"]:not([data-framerforms-no-prefill]),\n\t\t\t\t\t\ttextarea[name=\"${input.inputName}\"]:not([data-framerforms-no-prefill])`;// First try to find elements within the same form\nlet inputElement=form?.querySelector(query);// If no element found in form, or no form exists, search the entire document\nif(!inputElement){inputElement=document.querySelector(query);}if(inputElement){if(inputElement.tagName==\"INPUT\"&&inputElement.getAttribute(\"type\")==\"hidden\"){if(inputElement.hasAttribute(\"data-framerforms-set-value-event\")){inputElement.dispatchEvent(new CustomEvent(\"framerFormsSetValue\",{bubbles:true,detail:value}));}}else{const elementType=inputElement.tagName==\"INPUT\"?window.HTMLInputElement:inputElement.tagName==\"TEXTAREA\"?window.HTMLTextAreaElement:inputElement.tagName==\"SELECT\"?window.HTMLSelectElement:null;if(elementType){const nativeInputValueSetter=Object.getOwnPropertyDescriptor(elementType.prototype,\"value\").set;nativeInputValueSetter.call(inputElement,value);inputElement.dispatchEvent(new Event(\"input\",{bubbles:true}));}else{inputElement.value=value;}}}}}},0);return()=>clearTimeout(timer);},[]);return /*#__PURE__*/_jsx(HiddenComponentLabel,{ref:ref,id:id,text:\"Pre-fill Form Inputs\",subtext:Array.isArray(inputs)?inputs.map(input=>input.inputName).join(\", \"):\"\"});}PrefillFormInputs.displayName=\"Pre-fill Form Inputs Staging\";addPropertyControls(PrefillFormInputs,{inputs:{type:ControlType.Array,description:\"Fill input values from URL parameters\",control:{type:ControlType.Object,controls:{inputName:{type:ControlType.String,defaultValue:\"\",placeholder:\"Input Name\",preventLocalization:true},urlParameter:{type:ControlType.String,title:\"URL Param\",placeholder:\"URL Parameter\",preventLocalization:true}}}}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"PrefillFormInputs\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"any\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"* @framerDisableUnlink\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}"],"mappings":"kQAIG,SAAwB,EAAkB,EAAM,CAAC,GAAK,CAAC,UAAQ,EAAY,EAAS,EAAa,QAAQ,IAAI,EAAa,OAAa,EAAG,EAAc,EAAQ,EAAIA,EAAO,IAAI,EAagoB,OAb9nB,MAAc,CAClM,GAAG,GAAU,CAAC,MAAM,QAAQ,CAAM,GAAG,EAAO,SAAS,EAAG,O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