import{G as e,Pt as t,Tt as n,pt as r}from"./vue-vendor-DMUmTARL.js";import{rt as i}from"./index-BcZTP2Ia.js";var a=`login`,o=`zfile-turnstile-script`,s=`https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit`,c=300,l=e=>e.clientWidth<c?`compact`:`flexible`,u=(e,t)=>{let n=e.firstElementChild,r=e.querySelector(`iframe`);if(t===`compact`){n?.style.removeProperty(`width`),n?.style.removeProperty(`max-width`),r?.style.removeProperty(`width`),r?.style.setProperty(`max-width`,`100%`);return}n?.style.setProperty(`width`,`100%`),n?.style.setProperty(`max-width`,`100%`),r?.style.setProperty(`width`,`100%`),r?.style.setProperty(`max-width`,`100%`)},d=(e,t,n)=>{window.requestAnimationFrame(()=>{u(e,t),n()})},f=null,p=()=>window.turnstile?Promise.resolve(window.turnstile):f||(f=new Promise((e,t)=>{let n=document.getElementById(o);if(n){n.addEventListener(`load`,()=>{if(window.turnstile){e(window.turnstile);return}t(Error(`Turnstile 脚本加载完成，但 window.turnstile 不存在`))}),n.addEventListener(`error`,()=>{f=null,t(Error(`Turnstile 脚本加载失败`))});return}let r=document.createElement(`script`);r.id=o,r.src=s,r.async=!0,r.defer=!0,r.onload=()=>{if(window.turnstile){e(window.turnstile);return}f=null,t(Error(`Turnstile 脚本加载完成，但 window.turnstile 不存在`))},r.onerror=()=>{f=null,t(Error(`Turnstile 脚本加载失败`))},document.head.appendChild(r)}),f);function m(o,s=a){let c=i(),u=n(``),f=n(!1),m=n(!1),h=n(``),g=n(`flexible`),_=n(null),v=n(``),y=()=>{u.value=``,f.value=!1},b=async({preserveLoading:e=!1}={})=>{let n=t(o);if(!n){y(),_.value=null,e||(m.value=!1);return}if(_.value!==null)try{(await p()).remove(_.value)}catch{}n.innerHTML=``,_.value=null,y(),e||(m.value=!1)},x=async e=>{let n=t(o);if(!(!n||!e)){v.value=e,m.value=!0,h.value=``,g.value=l(n),await b({preserveLoading:!0});try{_.value=(await p()).render(n,{sitekey:e,action:s,size:g.value,theme:c.value?`dark`:`light`,callback:e=>{u.value=e,f.value=!0,d(n,g.value,()=>{m.value=!1})},"expired-callback":()=>{u.value=``,f.value=!1},"error-callback":e=>(u.value=``,f.value=!1,h.value=e?`验证失败 (${e})`:`验证失败`,m.value=!1,!0)}),d(n,g.value,()=>{m.value=!1})}catch(e){console.error(`[Turnstile] 组件渲染失败:`,e),m.value=!1,h.value=e instanceof Error?e.message:`组件渲染失败`,_.value=null}}};return r(c,()=>{_.value!==null&&v.value&&x(v.value)}),{turnstileToken:u,turnstileReady:f,turnstileLoading:m,turnstileError:h,turnstileWidgetSize:g,renderTurnstile:x,resetTurnstile:async()=>{let e=t(o);if(_.value===null){y(),m.value=!1;return}try{let t=await p();y(),m.value=!0,t.reset(_.value),e?d(e,g.value,()=>{m.value=!1}):m.value=!1}catch(e){console.error(`[Turnstile] 组件重置失败:`,e),m.value=!1}},retryTurnstile:()=>{v.value&&(h.value=``,m.value=!0,e(()=>{x(v.value)}))},removeTurnstile:b,cleanup:()=>{b()}}}export{m as t};