import{d as z,r as l,G as m,W as S,z as F,c as p,x as I,A as _,b as R,h as V,o as f,_ as B}from"./index-DqVhJ65C.js";const N={key:0,class:"text-gray-400 text-sm italic"},j={key:1,class:"tencent-captcha-hint text-gray-500 text-sm"},D=z({__name:"Captcha",props:{config:{}},emits:["success","close"],setup(g,{expose:w,emit:y}){const c=g,u=y,v=l(null),r=l(null),d=l(null),o=l(!1),n=l(!0),s=m(()=>{var e;return((e=c.config)==null?void 0:e.provider)||"none"}),i=m(()=>{var e;return((e=c.config)==null?void 0:e.enabled)&&s.value!=="none"}),C=()=>new Promise((e,a)=>{if(typeof window.initGeetest4=="function"){e();return}const t=document.createElement("script");t.src="https://static.geetest.com/v4/gt4.js",t.async=!0,t.onload=()=>e(),t.onerror=()=>a(new Error("Failed to load Geetest SDK")),document.head.appendChild(t)}),x=async()=>{var e;if((e=c.config)!=null&&e.captcha_id)try{await C(),window.initGeetest4({captchaId:c.config.captcha_id,product:"float",language:"zho",width:"100%"},a=>{r.value=a,window.geetestCaptcha=a,a.appendTo(v.value),a.onReady(()=>{o.value=!0,n.value=!1}),a.onSuccess(()=>{const t=a.getValidate();t&&u("success",{provider:"geetest",lot_number:t.lot_number,captcha_output:t.captcha_output,pass_token:t.pass_token,gen_time:t.gen_time})}),a.onError(t=>{console.error("Geetest error:",t),n.value=!1})})}catch(a){console.error("Failed to initialize Geetest:",a),n.value=!1}},T=()=>new Promise((e,a)=>{if(typeof window.TencentCaptcha=="function"){e();return}const t=document.createElement("script");t.src="https://turing.captcha.qcloud.com/TJCaptcha.js",t.async=!0,t.onload=()=>e(),t.onerror=()=>a(new Error("Failed to load Tencent Captcha SDK")),document.head.appendChild(t)}),k=async()=>{var e;if((e=c.config)!=null&&e.captcha_app_id)try{await T(),o.value=!0,n.value=!1}catch(a){console.error("Failed to load Tencent Captcha:",a),n.value=!1}},G=()=>{var e;if((e=c.config)!=null&&e.captcha_app_id)try{const a=new window.TencentCaptcha(c.config.captcha_app_id,t=>{t.ret===0?u("success",{provider:"tencent",ticket:t.ticket,randstr:t.randstr}):t.ret===2&&u("close")},{userLanguage:"zh-cn"});d.value=a,a.show()}catch(a){console.error("Tencent Captcha error:",a)}},E=()=>{if(!i.value){u("success",{provider:"geetest"});return}s.value==="geetest"&&r.value&&o.value?r.value.showCaptcha():s.value==="tencent"&&o.value&&G()},b=()=>{s.value==="geetest"&&r.value&&r.value.reset(),s.value==="tencent"&&d.value&&(d.value.destroy(),d.value=null)},h=async()=>{if(!i.value){n.value=!1;return}n.value=!0,s.value==="geetest"?await x():s.value==="tencent"&&await k()};return S(()=>c.config,e=>{e!=null&&e.enabled?h():(n.value=!1,o.value=!1)},{immediate:!0,deep:!0}),F(()=>{i.value&&h()}),w({verify:E,reset:b}),(e,a)=>(f(),p("div",{ref_key:"captchaRef",ref:v,class:I(["captcha-container",{"has-config":i.value}])},[n.value&&i.value?(f(),p("div",N," 正在加载验证组件... ")):_("",!0),s.value==="tencent"&&o.value?(f(),p("div",j,[...a[0]||(a[0]=[R("span",{class:"text-green-500"},"√",-1),V(" 腾讯云验证码已就绪 ",-1)])])):_("",!0)],2))}}),L=B(D,[["__scopeId","data-v-840d904e"]]);export{L as C};
