{"version":3,"file":"PrefillFormInputs.BjM_CwmR.mjs","names":["useRef","__esmMin","init_ssg_sandbox_shims","init_npm_react_18_3_1","window","ce","init_jsx_runtime","c","de","init_framer_D6uXRwWs","RenderTarget","addPropertyControls","ControlType","useInstanceId","HiddenComponentLabel","init_FramerFormsShared","PrefillFormInputs","props","isCanvas","id","ref","inputs","timer","urlSearchParams","urlParams","key","value","form","i","input","query","inputElement","elementType","init_PrefillFormInputs"],"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\"}}}"],"m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