{"version":3,"file":"FormSuccessSwap.ByZUT42P.mjs","names":["__esmMin","init_npm_react_18_3_1","init_jsx_runtime","c","ce","addPropertyControls","RenderTarget","init_framer_DcxuU94H","ControlType","FormSuccessSwap","props","norm","v","findSection","name","el","success","successName","debug","formSection","formName","armed","done","isVisible","r","s","labelShowing","label","target","root","reveal","hideForm","scrollTo","form","watchRoot","check","errorLabel","successLabel","onSubmit","observer","init_FormSuccessSwap"],"sources":["https:/framerusercontent.com/modules/NpKx5xwoNSWNE7nB1hvi/Q8BZkmBaeyeRYtuWCGri/FormSuccessSwap.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect}from\"react\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";/**\n * Form success swap — keeps a section hidden until the form on this page has\n * actually been submitted successfully, then reveals it.\n *\n * Two guards, because either alone gives false positives:\n *\n *  1. ARMED ONLY AFTER SUBMIT. Nothing is revealed until the form fires a\n *     `submit` event. Before that the watcher does not even look.\n *  2. VISIBLE TEXT ONLY. Framer renders every variant of a component into the\n *     DOM and hides the inactive ones, so the Submit Button's \"Thank you\"\n *     success variant is present from first paint. Matching on textContent\n *     therefore matches instantly. We only accept the label if the element\n *     carrying it is actually rendered (has layout boxes and is not hidden).\n *\n * The section stays visible in the Framer canvas so it is editable; it is\n * hidden at runtime on mount instead.\n *\n * @framerIntrinsicWidth 0\n * @framerIntrinsicHeight 0\n * @framerDisableUnlink\n * @framerSupportedLayoutWidth fixed\n * @framerSupportedLayoutHeight fixed\n */export default function FormSuccessSwap(props){const{successName,formName,successLabel,errorLabel,hideForm,scrollTo,debug}=props;useEffect(()=>{if(RenderTarget.current()===RenderTarget.canvas)return;if(typeof document===\"undefined\")return;const norm=v=>(v??\"\").toLowerCase().replace(/\\s+/g,\" \").trim();const findSection=name=>{if(!name)return null;const exact=document.querySelector(`[data-framer-name=\"${name.replace(/\"/g,'\\\\\"')}\"]`);if(exact)return exact;const all=Array.from(document.querySelectorAll(\"[data-framer-name]\"));return all.find(el=>norm(el.getAttribute(\"data-framer-name\"))===norm(name))??null;};const success=findSection(successName);if(!success){if(debug)console.log(\"[FormSuccessSwap] success section not found:\",successName);return;}const formSection=findSection(formName);success.style.display=\"none\";let armed=false;let done=false;const isVisible=el=>{if(!el.isConnected)return false;if(el.offsetParent===null&&getComputedStyle(el).position!==\"fixed\")return false;const r=el.getBoundingClientRect();if(r.width===0||r.height===0)return false;const s=getComputedStyle(el);return s.visibility!==\"hidden\"&&s.display!==\"none\"&&Number(s.opacity)>.01;};// a label counts only if some visible element actually shows it\nconst labelShowing=(root,label)=>{if(!label)return false;const target=norm(label);const els=Array.from(root.querySelectorAll(\"*\"));return els.some(el=>el.children.length===0&&norm(el.textContent)===target&&isVisible(el));};const reveal=()=>{if(done)return;done=true;success.style.display=\"\";if(hideForm&&formSection)formSection.style.display=\"none\";if(scrollTo){try{success.scrollIntoView({behavior:\"smooth\",block:\"center\"});}catch{success.scrollIntoView();}}if(debug)console.log(\"[FormSuccessSwap] revealed\");};const form=formSection?.closest(\"form\")??formSection?.querySelector(\"form\")??document.querySelector(\"form\");const watchRoot=form??document.body;const check=()=>{if(!armed||done)return;if(labelShowing(watchRoot,errorLabel)){if(debug)console.log(\"[FormSuccessSwap] error showing, holding\");return;}if(labelShowing(watchRoot,successLabel))reveal();};const onSubmit=()=>{armed=true;if(debug)console.log(\"[FormSuccessSwap] submit seen, watching for success\");check();};const target=form??document;target.addEventListener(\"submit\",onSubmit,true);const observer=new MutationObserver(check);observer.observe(watchRoot,{childList:true,subtree:true,characterData:true,attributes:true,attributeFilter:[\"style\",\"class\",\"hidden\"]});return()=>{observer.disconnect();target.removeEventListener(\"submit\",onSubmit,true);success.style.display=\"\";};},[successName,formName,successLabel,errorLabel,hideForm,scrollTo,debug]);return /*#__PURE__*/_jsx(\"div\",{style:{width:0,height:0,overflow:\"hidden\"},\"aria-hidden\":\"true\"});}FormSuccessSwap.defaultProps={successName:\"Success message\",formName:\"Tell us about the property\",successLabel:\"Thank you\",errorLabel:\"Something went wrong\",hideForm:true,scrollTo:true,debug:false};addPropertyControls(FormSuccessSwap,{successName:{type:ControlType.String,title:\"Show\",defaultValue:\"Success message\",description:\"Layer name of the section to reveal\"},formName:{type:ControlType.String,title:\"Hide\",defaultValue:\"Tell us about the property\",description:\"Layer name of the form section\"},successLabel:{type:ControlType.String,title:\"Success text\",defaultValue:\"Thank you\"},errorLabel:{type:ControlType.String,title:\"Error text\",defaultValue:\"Something went wrong\"},hideForm:{type:ControlType.Boolean,title:\"Hide form\",defaultValue:true},scrollTo:{type:ControlType.Boolean,title:\"Scroll to\",defaultValue:true},debug:{type:ControlType.Boolean,title:\"Log\",defaultValue:false}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"FormSuccessSwap\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutHeight\":\"fixed\",\"framerDisableUnlink\":\"* @framerSupportedLayoutWidth fixed\",\"framerContractVersion\":\"1\",\"framerIntrinsicWidth\":\"0\",\"framerIntrinsicHeight\":\"0\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./FormSuccessSwap.map"],"mappings":"A,kLAsBG,SAAwBS,EAAgB,EAAM,CAAC,GAAK,CAAC,cAAY,WAAS,eAAa,aAAW,WAAS,WAAS,SAAOC,EAC0wC,OADpwCN,MAAc,CAAwD,GAApDE,EAAa,QAAQ,IAAIA,EAAa,QAAiB,OAAO,SAAW,IAAY,OAAO,IAAMK,EAAK,IAAIC,GAAG,GAAA,CAAI,YAAY,CAAC,CAAC,QAAQ,OAAO,GAAG,CAAC,CAAC,KAAK,EAAQC,EAAY,GAAWC,EAA6B,SAAS,cAAc,sBAAsBA,EAAK,QAAQ,KAAK,KAAK,EAAE,GAAQ,IAA6B,MAAM,KAAK,SAAS,iBAAiB,oBAAoB,CAAY,CAAC,CAAC,KAAK,GAAIH,EAAKI,EAAG,aAAa,kBAAkB,CAAC,IAAIJ,EAAKG,CAA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