import{r as w,J as m,L as v,ac as y,j as h,g as _,i as x,P as a,M as T}from"./vendor-vue-gvI8EVHg.js";import{a as g}from"./index-DCLQfd0E.js";const k={key:0,class:"turnstile-wrapper"},K=w({__name:"TurnstileWidget",props:{siteKey:{},theme:{default:"auto"},size:{default:"flexible"}},emits:["verify","expire","error"],setup(l,{expose:d,emit:p}){const r=l,i=p,s=a(null),t=a(null),o=a(!1),f=()=>new Promise((e,u)=>{if(window.turnstile){o.value=!0,e();return}if(document.querySelector('script[src*="turnstile"]')){window.onTurnstileLoad=()=>{o.value=!0,e()};return}const n=document.createElement("script");n.src="https://challenges.cloudflare.com/turnstile/v0/api.js?onload=onTurnstileLoad",n.async=!0,n.defer=!0,window.onTurnstileLoad=()=>{o.value=!0,e()},n.onerror=()=>{u(new Error("Failed to load Turnstile script"))},document.head.appendChild(n)}),c=()=>{if(!(!window.turnstile||!s.value||!r.siteKey)){if(t.value){try{window.turnstile.remove(t.value)}catch{}t.value=null}s.value.innerHTML="",t.value=window.turnstile.render(s.value,{sitekey:r.siteKey,callback:e=>{i("verify",e)},"expired-callback":()=>{i("expire")},"error-callback":()=>{i("error")},theme:r.theme,size:r.size})}};return d({reset:()=>{window.turnstile&&t.value&&window.turnstile.reset(t.value)}}),m(async()=>{if(r.siteKey)try{await f(),c()}catch(e){console.error("Failed to initialize Turnstile:",e),i("error")}}),v(()=>{if(window.turnstile&&t.value)try{window.turnstile.remove(t.value)}catch{}}),y(()=>r.siteKey,e=>{e&&o.value&&c()}),(e,u)=>l.siteKey?(T(),h("div",k,[_("div",{ref_key:"containerRef",ref:s,class:"turnstile-container"},null,512)])):x("",!0)}}),B=g(K,[["__scopeId","data-v-8681e4fc"]]);export{B as T};
