{"version":3,"file":"AssuredForm.DgUiM_Az.mjs","names":["e"],"sources":["https:/framerusercontent.com/modules/z8Ux0L1DeJx3goT8Osk6/4nQPWISVk6l7CyObxZkR/AssuredForm.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{ControlType,addPropertyControls}from\"framer\";import React from\"react\";import{RenderTarget}from\"framer\";/**\n * AssuredForm\n * A form wrapper component with custom validation for `zipCode` and `currentAge`.\n */export default function AssuredForm(props){const childrenCount=React.Children.count(props.children);const children=React.Children.toArray(props.children);if(children.length===0){return /*#__PURE__*/_jsx(\"div\",{children:\"Need content\"});}if(children.length>1){return /*#__PURE__*/_jsx(\"div\",{children:\"only one child allowed\"});}const child=children[0];const isOnCanvas=RenderTarget.current()===RenderTarget.canvas;const{storage,...restProps}=props;if(isOnCanvas){return /*#__PURE__*/React.cloneElement(child,{...child.props,...restProps});}const initData=React.useMemo(()=>{try{return JSON.parse(sessionStorage.getItem(storage));}catch(e){return null;}},[storage]);const ref=React.useRef();React.useLayoutEffect(()=>{if(!ref.current){return;}if(initData&&typeof initData===\"object\"){for(const[key,value]of Object.entries(initData)){console.log(\"key: \",key,\"value: \",value);let el=ref.current.querySelector(`[name=${JSON.stringify(key)}]`);if(el){if(el.type===\"checkbox\"){el.checked=value===\"on\";}else if(el.type===\"radio\"){el=ref.current.querySelector(`[name=${JSON.stringify(key)}][value=${JSON.stringify(value)}]`);console.log(\"el: \",el);console.log(\"value: \",value);el.checked=el.value===value;}else{el.value=value;}}}}},[storage,initData]);return /*#__PURE__*/React.cloneElement(/*#__PURE__*/_jsx(\"form\",{}),{...child.props,...restProps,ref:ref,...{onSubmit:e=>{e.preventDefault();const form=e.currentTarget;if(!form){return;}// Locate the currentAge input field\nconst currentAgeInput=form.querySelector('input[name=\"currentAge\"]');if(currentAgeInput){const age=parseInt(currentAgeInput.value,10)// Convert input value to a number\n;// Check if the age is outside the range of 55-80\nif(isNaN(age)||age<55||age>80){currentAgeInput.setCustomValidity(\"Applicant age should be between 55-80.\");currentAgeInput.reportValidity();return;}else{currentAgeInput.setCustomValidity(\"\")// Clear validation message\n;}}const link=form.getAttribute(\"action\");if(!form.checkValidity()){form.reportValidity();return;}const formData=new FormData(form);sessionStorage.setItem(storage,JSON.stringify(Object.fromEntries(formData.entries())));if(!link){return;}window.location.href=`${link}${window.location.search}`;}}},React.Children.map(child.props.children,childElement=>{if(childElement.props?.name===\"currentAge\"){return /*#__PURE__*/React.cloneElement(childElement,{...childElement.props,min:55,max:80});}if(childElement.props.name===\"formChild\"){return /*#__PURE__*/React.cloneElement(childElement,{...childElement.props,style:{width:\"100% !important\",minWidth:\"100%\",maxWidth:\"100%\",...childElement.props.style}});}return childElement;}));}addPropertyControls(AssuredForm,{children:{type:ControlType.ComponentInstance},action:{type:ControlType.String},storage:{type:ControlType.String,description:\"What name to give this form in Session Storage\"}});export function withAssuredSubmit(Component){return props=>{return /*#__PURE__*/_jsx(Component,{...props,onClick:e=>{e.preventDefault();const btn=e.target;let parent=btn.parentNode;while(parent&&parent.tagName!==\"FORM\"){parent=parent.parentNode;}const form=parent;if(!form){return;}form.dispatchEvent(new Event(\"submit\",{cancelable:true,bubbles:true}));}});};}\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"AssuredForm\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"withAssuredSubmit\":{\"type\":\"reactHoc\",\"name\":\"withAssuredSubmit\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./AssuredForm.map"],"mappings":"2TAGG,SAAwB,EAAY,EAAM,CAAC,IAAM,EAAc,EAAM,SAAS,MAAM,EAAM,SAAS,CAAO,EAAS,EAAM,SAAS,QAAQ,EAAM,SAAS,CAAC,GAAG,EAAS,SAAS,EAAG,MAAoB,GAAK,MAAM,CAAC,SAAS,cAAe,EAAC,CAAE,GAAG,EAAS,OAAO,EAAG,MAAoB,G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