{"version":3,"file":"Demo_Form.sdbYG67P.mjs","names":["useState"],"sources":["https:/framerusercontent.com/modules/Z98jpVJkost5xTkHL38i/x4DtskAtAJuLKtbKmWCl/Demo_Form.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import*as React from\"react\";import{forwardRef,useState,useEffect}from\"react\";import{addPropertyControls,ControlType}from\"framer\";// Import for Property Controls\nexport function withCustomId(Component){return /*#__PURE__*/forwardRef((props,ref)=>{// We'll use a useEffect to apply the ID once the component is mounted\n// and its ref is available.\nReact.useEffect(()=>{if(ref&&ref.current&&props.id){const element=ref.current;element.id=props.id;// console.log(`Set ID \"${props.id}\" on element:`, element); // For debugging\n}},[props.id,ref])// Re-run if ID or ref changes\n;// Pass all original props and the ref to the wrapped component\nreturn /*#__PURE__*/_jsx(Component,{ref:ref,...props});});}// Add Property Controls so you can set the ID from the Framer canvas\naddPropertyControls(withCustomId,{id:{type:ControlType.String,title:\"Custom ID\",defaultValue:\"takeDemo\",placeholder:\"e.g., myContactForm\",displayTextArea:false}});export function withFormSubmitLogic(Component){return /*#__PURE__*/forwardRef((props,ref)=>{const[formErrors,setFormErrors]=useState({});const[submissionAttempted,setSubmissionAttempted]=useState(false);// Get the ID passed from the `withCustomId` override\n// Assuming your form component receives `id` as a prop because `withCustomId`\n// is applied to it, and passes it down.\nconst formId=props.id||\"takeDemo\"// Use the ID from props or a default\n;const getForm=()=>{// Prefer getting by the assigned ID\nconst formById=document.getElementById(formId);if(formById)return formById;// Fallback: If no ID or ID not found, try getting the first form\nif(document.forms.length>0){console.warn(`Form with ID \"${formId}\" not found. Falling back to document.forms[0]. Please ensure the form has the correct ID assigned via 'withCustomId' override.`);return document.forms[0];}return null;};// ... (rest of your validateForm and handleTap functions) ...\nconst validateForm=form=>{const errors={};let isValid=true;const formData=new FormData(form);// Access inputs by their 'name' attribute\nconst name=formData.get(\"name\");if(!name||typeof name===\"string\"&&name.trim()===\"\"){isValid=false;errors.name=\"Name is required.\";}const email=formData.get(\"email\");const emailRegex=/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;if(!email||typeof email===\"string\"&&!emailRegex.test(email.trim())){isValid=false;errors.email=\"Please enter a valid email address.\";}const phone_number=formData.get(\"phone_number\");if(!phone_number||typeof phone_number===\"string\"&&phone_number.trim()===\"\"){isValid=false;errors.phone_number=\"Phone Number is required.\";}const company_name=formData.get(\"company_name\");if(!company_name||typeof company_name===\"string\"&&company_name.trim()===\"\"){isValid=false;errors.company_name=\"Company Name is required.\";}return{isValid,errors};};const handleTap=()=>{setSubmissionAttempted(true);try{const form=getForm();if(!form){console.error(\"Framer Form not found! Please ensure it has a custom ID and is correctly applied.\");// alert(\"Form not found. Please contact support.\")\nreturn;}const{isValid,errors}=validateForm(form);setFormErrors(errors);if(!isValid){console.warn(\"Form validation failed:\",errors);let errorMessages=Object.values(errors).join(\"\\n\");if(errorMessages){// alert(\"Please correct the following errors:\\n\" +errorMessages)\n}else{// alert(\"There were validation errors. Please check the form.\")\n}// Optional: Add visual error classes directly here if you can't rely on useEffect for some reason\nObject.keys(errors).forEach(fieldName=>{const input=form.elements.namedItem(fieldName);if(input){input.classList.add(\"input-error\");}});return;}// Remove error classes on successful validation\nObject.keys(formErrors).forEach(fieldName=>{const input=form.elements.namedItem(fieldName);if(input){input.classList.remove(\"input-error\");}});const formData=new FormData(form);let data={};for(const pair of formData.entries()){data[pair[0]]=pair[1];}localStorage.setItem(\"demoFormData\",JSON.stringify(data));console.log(\"Form data saved:\",data);window.location.href=\"/demo-agents\";}catch(error){console.error(\"Error during form submission or validation:\",error);// alert(\"An unexpected error occurred. Please try again.\")\n}};// This useEffect will run when formErrors change, useful for dynamic error displays\nuseEffect(()=>{const form=getForm();if(!form)return;// Apply/remove 'input-error' class based on formErrors state\nArray.from(form.elements).forEach(element=>{const input=element;if(input.name&&formErrors[input.name]){input.classList.add(\"input-error\");}else if(input.name){input.classList.remove(\"input-error\");}});// You could also attempt to insert/update error message text next to inputs here,\n// but that's more complex as it involves creating/finding DOM elements dynamically.\n},[formErrors,submissionAttempted])// Also re-run on submission attempt to clear errors initially\n;return /*#__PURE__*/_jsx(Component,{ref:ref,...props,onClick:handleTap});});}export function withAccessControl(Component){return /*#__PURE__*/forwardRef((props,ref)=>{const localStoragePresent=localStorage.getItem(\"demoFormData\");if(!localStoragePresent){window.location.href=\"/demo\";return null;}return /*#__PURE__*/_jsx(Component,{ref:ref,...props});});}export function withPhoneNumber(Component){return /*#__PURE__*/forwardRef((props,ref)=>{const formData=localStorage.getItem(\"demoFormData\");let phone_number=\"\";if(formData){let jsonFormData=JSON.parse(formData);phone_number=jsonFormData.phone_number;console.log(formData);console.log(phone_number);props[\"value\"]=phone_number;}return /*#__PURE__*/_jsx(Component,{ref:ref,...props,defaultValue:phone_number,value:phone_number});});}\nexport const __FramerMetadata__ = {\"exports\":{\"withAccessControl\":{\"type\":\"reactHoc\",\"name\":\"withAccessControl\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withCustomId\":{\"type\":\"reactHoc\",\"name\":\"withCustomId\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withPhoneNumber\":{\"type\":\"reactHoc\",\"name\":\"withPhoneNumber\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withFormSubmitLogic\":{\"type\":\"reactHoc\",\"name\":\"withFormSubmitLogic\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Demo_Form.map"],"mappings":"iMACA,SAAgB,EAAa,EAAU,CAAC,OAAoB,GAAY,EAAM,KAE9E,MAAoB,CAAC,GAAG,GAAK,EAAI,SAAS,EAAM,GAAG,CAAC,IAAM,EAAQ,EAAI,QAAQ,EAAQ,GAAG,EAAM,KAC5F,CAAC,EAAM,GAAG,EAAI,CAAC,CAEE,EAAK,EAAU,CAAK,MAAI,GAAG,EAAM,CAAC,EAAG,CAC0G,SAAgB,EAAoB,EAAU,CAAC,OAAoB,GAAY,EAAM,IAAM,CA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