{"version":3,"file":"Recapcha.CD3NFOkK.mjs","names":["useRef","useState"],"sources":["https:/framerusercontent.com/modules/eEZyrWTK2vuqmpLgHG4O/L0Bu9ceLs5JNxgDDn7Uh/Recapcha.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useEffect,useRef,useState}from\"react\";import{addPropertyControls,ControlType}from\"framer\";export default function Recaptcha(props){const{siteKey,theme,size,fieldName,required,errorMessage,onVerify,onExpire,onError}=props;const recaptchaRef=useRef(null);const widgetIdRef=useRef(null);const hiddenInputRef=useRef(null);const containerRef=useRef(null);const[isLoaded,setIsLoaded]=useState(false);const[error,setError]=useState(null);const[token,setToken]=useState(\"\");const[showValidationError,setShowValidationError]=useState(false);// Prevent form submission if reCAPTCHA not completed\nuseEffect(()=>{if(!required)return;const handleFormSubmit=e=>{if(!token){e.preventDefault();e.stopPropagation();e.stopImmediatePropagation();setShowValidationError(true);// Scroll to reCAPTCHA\nif(containerRef.current){containerRef.current.scrollIntoView({behavior:\"smooth\",block:\"center\"});}return false;}};const handleClick=e=>{const target=e.target;const isSubmitButton=target.tagName===\"BUTTON\"&&(target.getAttribute(\"type\")===\"submit\"||!target.getAttribute(\"type\"));if(isSubmitButton&&!token){e.preventDefault();e.stopPropagation();e.stopImmediatePropagation();setShowValidationError(true);if(containerRef.current){containerRef.current.scrollIntoView({behavior:\"smooth\",block:\"center\"});}return false;}};// Find the parent form\nlet formElement=containerRef.current?.closest(\"form\");if(formElement){// Add multiple event listeners for maximum coverage\nformElement.addEventListener(\"submit\",handleFormSubmit,true);formElement.addEventListener(\"click\",handleClick,true);// Also disable submit button if no token\nconst submitButton=formElement.querySelector('button[type=\"submit\"], button:not([type])');return()=>{formElement?.removeEventListener(\"submit\",handleFormSubmit,true);formElement?.removeEventListener(\"click\",handleClick,true);};}},[token,required]);// Set initial custom validity\nuseEffect(()=>{if(required&&hiddenInputRef.current&&!token){if(hiddenInputRef.current.setCustomValidity){hiddenInputRef.current.setCustomValidity(errorMessage||\"Please complete the reCAPTCHA verification\");}}},[required,errorMessage]);useEffect(()=>{// Check if site key is provided\nif(!siteKey){setError(\"Please provide a site key\");return;}// Load reCAPTCHA script\nconst loadRecaptcha=()=>{if(window.grecaptcha){setIsLoaded(true);return;}const script=document.createElement(\"script\");script.src=\"https://www.google.com/recaptcha/api.js?render=explicit\";script.async=true;script.defer=true;script.onload=()=>{setIsLoaded(true);};script.onerror=()=>{setError(\"Failed to load reCAPTCHA script\");};document.head.appendChild(script);};loadRecaptcha();},[siteKey]);useEffect(()=>{if(!isLoaded||!recaptchaRef.current||!siteKey)return;// Wait for grecaptcha to be ready\nconst renderRecaptcha=()=>{if(window.grecaptcha&&window.grecaptcha.render){try{// If widget exists and theme/size changed, remove and re-render\nif(widgetIdRef.current!==null){// Get the container and clear it completely\nif(recaptchaRef.current){recaptchaRef.current.innerHTML=\"\";}widgetIdRef.current=null;}// Render new reCAPTCHA\nconsole.log(`Rendering reCAPTCHA with theme: ${theme}, size: ${size}`);widgetIdRef.current=window.grecaptcha.render(recaptchaRef.current,{sitekey:siteKey,theme:theme,size:size,callback:verificationToken=>{console.log(\"reCAPTCHA verified:\",verificationToken);setToken(verificationToken);setShowValidationError(false);// Update hidden input for form submission\nif(hiddenInputRef.current){hiddenInputRef.current.value=verificationToken;// Clear custom validity\nif(hiddenInputRef.current.setCustomValidity){hiddenInputRef.current.setCustomValidity(\"\");}// Trigger validation update for Framer Forms\nconst event=new Event(\"input\",{bubbles:true});hiddenInputRef.current.dispatchEvent(event);}if(onVerify){onVerify(verificationToken);}},\"expired-callback\":()=>{console.log(\"reCAPTCHA expired\");setToken(\"\");setShowValidationError(required);// Clear hidden input\nif(hiddenInputRef.current){hiddenInputRef.current.value=\"\";// Set custom validity\nif(hiddenInputRef.current.setCustomValidity){hiddenInputRef.current.setCustomValidity(errorMessage||\"Please complete the reCAPTCHA verification\");}const event=new Event(\"input\",{bubbles:true});hiddenInputRef.current.dispatchEvent(event);}if(onExpire){onExpire();}},\"error-callback\":()=>{console.log(\"reCAPTCHA error\");setToken(\"\");setShowValidationError(required);// Set custom validity for error\nif(hiddenInputRef.current&&hiddenInputRef.current.setCustomValidity){hiddenInputRef.current.setCustomValidity(errorMessage||\"Please complete the reCAPTCHA verification\");}if(onError){onError();}}});}catch(err){setError(\"Failed to render reCAPTCHA\");console.error(err);}}};// Check if grecaptcha is ready\nif(window.grecaptcha&&window.grecaptcha.render){renderRecaptcha();}else{// Wait for grecaptcha to be ready\nconst checkInterval=setInterval(()=>{if(window.grecaptcha&&window.grecaptcha.render){renderRecaptcha();clearInterval(checkInterval);}},100);return()=>clearInterval(checkInterval);}return()=>{if(widgetIdRef.current!==null&&window.grecaptcha){try{window.grecaptcha.reset(widgetIdRef.current);}catch(err){console.error(\"Error resetting reCAPTCHA:\",err);}}};},[isLoaded,siteKey,theme,size,required,errorMessage,onVerify,onExpire,onError]);if(error){return /*#__PURE__*/_jsxs(\"div\",{style:{padding:\"20px\",backgroundColor:\"#fee\",border:\"1px solid #fcc\",borderRadius:\"4px\",color:\"#c33\",fontFamily:\"sans-serif\",fontSize:\"14px\"},children:[/*#__PURE__*/_jsx(\"strong\",{children:\"Error:\"}),\" \",error]});}if(!siteKey){return /*#__PURE__*/_jsxs(\"div\",{style:{padding:\"20px\",backgroundColor:\"#fef3cd\",border:\"1px solid #ffc107\",borderRadius:\"4px\",color:\"#856404\",fontFamily:\"sans-serif\",fontSize:\"14px\"},children:[/*#__PURE__*/_jsx(\"strong\",{children:\"Configuration Required:\"}),\" Please add your reCAPTCHA site key in the component properties.\"]});}return /*#__PURE__*/_jsxs(\"div\",{ref:containerRef,style:{display:\"inline-block\",width:\"100%\",padding:showValidationError&&required&&!token?\"8px\":\"0\",border:showValidationError&&required&&!token?\"2px solid #dc3545\":\"none\",borderRadius:\"4px\",backgroundColor:showValidationError&&required&&!token?\"#fff5f5\":\"transparent\",transition:\"all 0.3s ease\"},children:[/*#__PURE__*/_jsx(\"div\",{ref:recaptchaRef}),/*#__PURE__*/_jsx(\"input\",{ref:hiddenInputRef,type:\"text\",name:fieldName||\"g-recaptcha-response\",value:token,required:required,\"data-recaptcha\":\"true\",\"aria-label\":\"reCAPTCHA response token\",style:{position:\"absolute\",opacity:0,pointerEvents:\"none\",height:0,width:0},onInvalid:e=>{e.preventDefault();setShowValidationError(true);if(containerRef.current){containerRef.current.scrollIntoView({behavior:\"smooth\",block:\"center\"});}}}),showValidationError&&required&&!token&&/*#__PURE__*/_jsxs(\"div\",{style:{marginTop:\"8px\",padding:\"12px\",backgroundColor:\"#fee\",border:\"1px solid #fcc\",borderRadius:\"4px\",color:\"#c33\",fontSize:\"14px\",fontFamily:\"system-ui, -apple-system, sans-serif\",fontWeight:\"500\",display:\"flex\",alignItems:\"center\",gap:\"8px\"},children:[/*#__PURE__*/_jsx(\"span\",{style:{fontSize:\"18px\"},children:\"⚠️\"}),/*#__PURE__*/_jsx(\"span\",{children:errorMessage||\"Please complete the reCAPTCHA verification\"})]})]});}// Add property controls for Framer\naddPropertyControls(Recaptcha,{siteKey:{type:ControlType.String,title:\"Site Key\",description:\"Your reCAPTCHA site key\",defaultValue:\"\"},fieldName:{type:ControlType.String,title:\"Field Name\",description:\"Form field name (default: g-recaptcha-response)\",defaultValue:\"g-recaptcha-response\"},required:{type:ControlType.Boolean,title:\"Required\",description:\"Make this field required in the form\",defaultValue:true},errorMessage:{type:ControlType.String,title:\"Error Message\",description:\"Message shown when validation fails\",defaultValue:\"Please complete the reCAPTCHA verification\",hidden:props=>!props.required},theme:{type:ControlType.Enum,title:\"Theme\",options:[\"light\",\"dark\"],optionTitles:[\"Light\",\"Dark\"],defaultValue:\"light\"},size:{type:ControlType.Enum,title:\"Size\",options:[\"normal\",\"compact\"],optionTitles:[\"Normal\",\"Compact\"],defaultValue:\"normal\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"Recaptcha\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"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