import{G as e}from"./p-CrfXJRIo.js";async function o(o,r,t,i,n,a){var c;try{if(await function(e){return new Promise(((o,r)=>{if(document.querySelector("#recaptcha-script"))o();else{const t=document.createElement("script");t.src=`https://www.google.com/recaptcha/api.js?render=${e}`,t.id="recaptcha-script",t.async=!0,t.onload=()=>{o()},t.onerror=e=>{console.error("Failed to load reCAPTCHA script",e),r(new Error("Failed to load reCAPTCHA script. Invalid siteKey or network error."))},document.head.appendChild(t)}}))}(r),await new Promise(((e,o)=>{window.grecaptcha&&"function"==typeof window.grecaptcha.ready?window.grecaptcha.ready((()=>e())):o(new Error("grecaptcha not available or ready() not a function"))})),!window.grecaptcha||"function"!=typeof window.grecaptcha.execute)throw new Error("grecaptcha.execute is not available. Possibly due to invalid site key.");const a=await window.grecaptcha.execute(r,{action:"open_chat"});if(!a)throw new Error("reCAPTCHA token is empty. Possibly invalid site key.");const c=await async function(o,r,t,i,n){try{const a={apiKey:i,configId:r,configType:t,token:o},c=await e(a,n);if(null==c?void 0:c.success)return c;{const e={message:`${t} verification failed`,codes:null==c?void 0:c["error-codes"],error:c};console.warn(`${t} activity suspected. Verification failed.`,e.codes);const o=new Error(`${t} verification failed: reCAPTCHA was unsuccessful`);throw o.detail=e,o}}catch(e){throw console.error("Failed to contact backend for reCAPTCHA verification:",e),(null==e?void 0:e.detail)||(e.detail={message:"reCAPTCHA backend error",error:e}),e}}(a,o,t,i,n);return c}catch(e){const o=null!==(c=null==e?void 0:e.detail)&&void 0!==c?c:{message:e instanceof Error?e.message:"reCAPTCHA execution failed",error:e};throw null==a||a(o),console.error("executeRecaptcha error:",e),e}}export{o as e}