;(function(document){
'use strict';
let isExecuting=false;
function executeRecaptcha(onSuccess, onError){
if(typeof grecaptcha==='undefined'||typeof grecaptcha.ready!=='function'){
console.warn('reCAPTCHA not loaded yet, skipping validation');
if(onError){
onError('reCAPTCHA not loaded');
}
return;
}
isExecuting=true;
grecaptcha.ready(function (){
try {
grecaptcha
.execute(globalThis.EDDreCAPTCHA.sitekey, {
action: globalThis.EDDreCAPTCHA.action,
})
.then(( token)=> {
const input=document.getElementById('edd-blocks-recaptcha');
if(input){
input.value=token;
}
isExecuting=false;
if(onSuccess){
onSuccess(token);
}})
.catch(( error)=> {
console.error('reCAPTCHA execution error:', error);
isExecuting=false;
if(onError){
onError(error);
}});
} catch(error){
console.error('reCAPTCHA error:', error);
isExecuting=false;
if(onError){
onError(error);
}}
});
}
globalThis.EDDCaptchaHandler={
execute: function(onSuccess, onError){
if(! globalThis.EDDreCAPTCHA.sitekey){
return;
}
if(isExecuting){
console.warn('CAPTCHA execution already in progress');
return;
}
executeRecaptcha(onSuccess, onError);
},
needsRefresh: true,
};})(document);