{"version":3,"file":"FormSpark_4.C2eDHozF.mjs","names":["useState","useCallback"],"sources":["https:/framerusercontent.com/modules/oYWQjsVOzXw1K3Ht6RSB/VbbEokiwwghYD8fEBGLC/FormSpark_4.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{addPropertyControls,ControlType}from\"framer\";import{motion}from\"framer-motion\";import{useState,useCallback}from\"react\";// Email Validation Regex\nconst emailRegex=/^(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/;const validateEmail=email=>emailRegex.test(email);// FormSpark Component\nexport default function FormSpark(props){const{formId,withName,withEmail,withPincode,withPhone,namePlaceholder,emailPlaceholder,pincodePlaceholder,phonePlaceholder,buttonLabel,gap,inputs,button}=props;// State Management\nconst[formData,setFormData]=useState({name:\"\",email:\"\",pincode:\"\",phone:\"\"});const[errors,setErrors]=useState({name:false,email:false,pincode:false,phone:false});const[errorMessage,setErrorMessage]=useState(\"\");const[isSuccess,setIsSuccess]=useState(false);const[isLoading,setIsLoading]=useState(false);const[showPopup,setShowPopup]=useState(false)// Overlay Popup State\n;// Handle Input Change\nconst handleChange=e=>{const{name,value}=e.target;// Restrict length for pincode and phone\nif(name===\"pincode\"&&value.length>6)return;if(name===\"phone\"&&value.length>10)return;setFormData({...formData,[name]:value});setErrors({...errors,[name]:false});};// Form Validation\nconst validateForm=useCallback(()=>{let hasError=false;const newErrors={name:false,email:false,pincode:false,phone:false};if(withName&&!formData.name.trim()){newErrors.name=hasError=true;setErrorMessage(\"Please enter a valid name.\");}if(withEmail&&(!formData.email.trim()||!validateEmail(formData.email))){newErrors.email=hasError=true;setErrorMessage(\"Please enter a valid email address.\");}if(withPincode&&(!formData.pincode.trim()||!/^\\d{6}$/.test(formData.pincode))){newErrors.pincode=hasError=true;setErrorMessage(\"Please enter a valid 6-digit pincode.\");}if(withPhone&&(!formData.phone.trim()||!/^\\d{10}$/.test(formData.phone))){newErrors.phone=hasError=true;setErrorMessage(\"Please enter a valid 10-digit phone number.\");}setErrors(newErrors);return hasError;},[formData,withName,withEmail,withPincode,withPhone]);// Handle Form Submission\nconst handleSubmit=useCallback(e=>{e.preventDefault();setIsLoading(true);if(validateForm()){setIsLoading(false);return;}fetch(`https://api.formspark.io/${formId}`,{method:\"POST\",headers:{\"Content-Type\":\"application/json\"},body:JSON.stringify(formData)}).then(()=>{setIsSuccess(true);setIsLoading(false);setShowPopup(true)// Show Popup on Success\n;}).catch(()=>setIsLoading(false));},[formId,formData,validateForm]);// Close Popup\nconst closePopup=()=>setShowPopup(false);return /*#__PURE__*/_jsxs(motion.div,{style:{display:\"grid\",gap:`${gap}px`},children:[/*#__PURE__*/_jsxs(\"form\",{onSubmit:handleSubmit,style:{display:\"grid\",gap:`${gap}px`},children:[errorMessage&&/*#__PURE__*/_jsx(\"div\",{style:errorPopupStyle,children:errorMessage}),withName&&/*#__PURE__*/_jsx(\"input\",{type:\"text\",name:\"name\",placeholder:namePlaceholder,value:formData.name,onChange:handleChange,style:inputStyle(inputs,errors.name)},\"name\"// Added unique key\n),withEmail&&/*#__PURE__*/_jsx(\"input\",{type:\"email\",name:\"email\",placeholder:emailPlaceholder,value:formData.email,onChange:handleChange,style:inputStyle(inputs,errors.email)},\"email\"// Added unique key\n),withPincode&&/*#__PURE__*/_jsx(\"input\",{type:\"text\",name:\"pincode\",placeholder:pincodePlaceholder,value:formData.pincode,onChange:handleChange,style:inputStyle(inputs,errors.pincode)},\"pincode\"// Added unique key\n),withPhone&&/*#__PURE__*/_jsx(\"input\",{type:\"tel\",name:\"phone\",placeholder:phonePlaceholder,value:formData.phone,onChange:handleChange,style:inputStyle(inputs,errors.phone)},\"phone\"// Added unique key\n),/*#__PURE__*/_jsx(\"button\",{type:\"submit\",style:buttonStyle(button),disabled:isLoading,children:isLoading?\"Submitting...\":buttonLabel})]}),showPopup&&/*#__PURE__*/_jsx(motion.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},style:overlayStyle,children:/*#__PURE__*/_jsxs(\"div\",{style:popupContentStyle,children:[/*#__PURE__*/_jsx(\"h3\",{children:\"Thank You!\"}),/*#__PURE__*/_jsx(\"p\",{children:\"Our Team will Reach out to You Soon!\"}),/*#__PURE__*/_jsx(\"button\",{onClick:closePopup,style:popupButtonStyle,children:\"Close\"})]})})]});}// Input, Button, and Popup Styles\nconst inputStyle=(inputs,hasError)=>({width:\"100%\",padding:\"10px\",borderRadius:\"5px\",fontSize:\"16px\",backgroundColor:(inputs===null||inputs===void 0?void 0:inputs.fill)||\"#f0f0f0\",border:`1px solid ${hasError?\"#ff4d4f\":\"#d9d9d9\"}`,outline:\"none\",boxShadow:hasError?\"0 0 0 2px rgba(255,77,79,0.2)\":\"none\"});const buttonStyle=button=>({padding:\"10px 20px\",backgroundColor:(button===null||button===void 0?void 0:button.fill)||\"#000\",color:(button===null||button===void 0?void 0:button.color)||\"#fff\",borderRadius:\"5px\",border:\"none\",cursor:\"pointer\",fontSize:\"16px\"});const overlayStyle={position:\"fixed\",top:0,left:0,width:\"100%\",height:\"100%\",backgroundColor:\"rgba(0, 0, 0, 0.6)\",display:\"flex\",alignItems:\"center\",justifyContent:\"center\",zIndex:9999};const popupContentStyle={backgroundColor:\"#fff\",padding:\"20px\",borderRadius:\"10px\",textAlign:\"center\",width:\"300px\",boxShadow:\"0 4px 10px rgba(0, 0, 0, 0.1)\"};const popupButtonStyle={marginTop:\"15px\",padding:\"10px 20px\",backgroundColor:\"#000\",color:\"#fff\",borderRadius:\"5px\",border:\"none\",cursor:\"pointer\",fontSize:\"16px\"};const errorPopupStyle={color:\"#ff4d4f\",fontSize:\"14px\",textAlign:\"center\",marginBottom:\"10px\"};// Add Framer Property Controls\naddPropertyControls(FormSpark,{formId:{title:\"Form ID\",type:ControlType.String,defaultValue:\"\"},withName:{title:\"Name Field\",type:ControlType.Boolean,defaultValue:true},namePlaceholder:{title:\"Name Placeholder\",type:ControlType.String,defaultValue:\"Your Name\"},withEmail:{title:\"Email Field\",type:ControlType.Boolean,defaultValue:true},emailPlaceholder:{title:\"Email Placeholder\",type:ControlType.String,defaultValue:\"Your Email\"},withPincode:{title:\"Pincode Field\",type:ControlType.Boolean,defaultValue:true},pincodePlaceholder:{title:\"Pincode Placeholder\",type:ControlType.String,defaultValue:\"Your Pincode\"},withPhone:{title:\"Phone Field\",type:ControlType.Boolean,defaultValue:true},phonePlaceholder:{title:\"Phone Placeholder\",type:ControlType.String,defaultValue:\"Your Phone\"},buttonLabel:{title:\"Button Label\",type:ControlType.String,defaultValue:\"Submit\"},gap:{title:\"Field Gap\",type:ControlType.Number,defaultValue:10},inputs:{type:ControlType.Object,defaultValue:{}},button:{type:ControlType.Object,defaultValue:{}}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"FormSpark\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./FormSpark_4.map"],"mappings":"iWAEA,SAAwB,EAAU,EAAM,CAAC,GAAK,CAAC,SAAO,WAAS,YAAU,cAAY,YAAU,kBAAgB,mBAAiB,qBAAmB,mBAAiB,cAAY,MAAI,SAAO,UAAQ,EAC9L,CAAC,EAAS,GAAaA,EAAS,CAAC,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,CAAC,CAAM,CAAC,EAAO,GAAWA,EAAS,CAAC,KAAK,GAAM,MAAM,GAAM,QAAQ,GAAM,MAAM,GAAM,CAAC,CAAM,CAAC,EAAa,GAAiBA,EAAS,GAAG,CAAM,CAAC,EAAU,GAAcA,EAAS,GAAM,CAAM,CAAC,EAAU,GAAcA,EAAS,GAAM,CAAM,CAAC,EAAU,GAAcA,EAAS,GAAM,CAEtV,EAA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