import{a as e,o as t,t as n}from"./i18n-CjHYiQIU.js";var r=t(),i=e();function a({siteKey:e,onToken:t,onError:a}){let{turnstileWidget:o}=n().strings,s=(0,r.useRef)(null),c=(0,r.useId)();return(0,r.useEffect)(()=>{if(!e||!s.current)return;let n=``,r=()=>{s.current&&window.turnstile&&(n=window.turnstile.render(s.current,{sitekey:e,callback:t,"error-callback":()=>a(o.failed)}))},i=document.querySelector(`script[data-thornlock-turnstile]`);if(window.turnstile)r();else if(i)i.addEventListener(`load`,r,{once:!0});else{let e=document.createElement(`script`);e.src=`https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit`,e.async=!0,e.dataset.thornlockTurnstile=`true`,e.addEventListener(`load`,r,{once:!0}),e.addEventListener(`error`,()=>a(o.unavailable),{once:!0}),document.head.append(e)}return()=>{n&&window.turnstile?.remove(n)}},[o,a,t,e]),(0,i.jsx)(`div`,{id:c,ref:s,className:`turnstile-host`,"aria-label":o.label})}export{a as t};