import{o as e}from"./rolldown-runtime-iuO8RvI4.js";import{ay as r,fl as t}from"./shared-0-C4kdVF7Y.js";import{Mi as i,ki as o}from"./vendor-frame-CwiylG4Y.js";import{Ju as c}from"./shared-1-3-6x7RKF.js";import{i as n,r as a}from"./c5c18ef72-DFl2CbZZ.js";var s,d=o(),u=e(i());function l({sitekeyStateOverride:e,allowDesktop:i=!1}={}){const{setHcaptchaToken:o,registerWidgetReset:l,registerTokenMinter:v,setChallengeOpen:f}=a(),h=(0,u.useRef)(null),p=(0,u.useRef)(void 0),m=(0,u.useRef)({}),w=(0,u.useRef)([]),k=(0,u.useRef)(void 0),y=(0,u.useRef)(void 0),b=t(),g=c({allowDesktop:i&&void 0!==e});let R;return R=void 0!==e?g?e:"":b?"pending":g&&r("signup_hcaptcha_token_collected",!1)?r("hcaptcha_sitekey",""):"",(0,u.useEffect)(()=>(v(()=>{if(y.current)return y.current;const e=(()=>{const e=m.current;return e.ready?Promise.resolve(e.ready):e.off?Promise.resolve(void 0):new Promise(e=>{w.current.push(e)})})().then(e=>new Promise(r=>{if(e){k.current=r;try{e.api.execute(e.id)}catch{k.current=void 0,r(void 0)}}else r(void 0)})).finally(()=>{y.current===e&&(y.current=void 0)});return y.current=e,e}),()=>{v(void 0),k.current?.(void 0),k.current=void 0}),[]),(0,u.useEffect)(()=>{if("pending"===R)return;const e=e=>{m.current=e?{ready:e}:{off:!0},w.current.splice(0).forEach(r=>r(e))};if(""===R)return e(void 0),()=>{m.current={}};const r=R;let t,i=!1;const c=()=>{void 0!==t&&(clearTimeout(t),t=void 0)},a=e=>{c(),k.current?.(e),k.current=void 0};return("undefined"!=typeof window&&window.hcaptcha?Promise.resolve(window.hcaptcha):(s??=n("__antClientAttestationHcaptchaInvisibleReady","client-attestation-hcaptcha-invisible-script").catch(e=>{throw s=void 0,e}),s)).then(n=>{if(i||!h.current)return void(i||e(void 0));let s=!1;const d=()=>{i||o(void 0)},u=n.render(h.current,{sitekey:r,size:"invisible",callback:e=>{i||(f(!1),o(e),a(e))},"expired-callback":()=>{d(),a(void 0)},"chalexpired-callback":()=>{f(!1),d(),a(void 0)},"error-callback":()=>{s=!0,f(!1),d(),a(void 0)},"open-callback":()=>{i||f(!0)},"close-callback":()=>{if(i)return;c();const e=k.current;t=setTimeout(()=>{t=void 0,i||k.current===e&&(f(!1),a(void 0))},2e3)}});void 0!==u?(p.current=u,i||s?i||e(void 0):(l(()=>{try{y.current=void 0,a(void 0),n.reset(u)}catch{}}),e({api:n,id:u}))):e(void 0)}).catch(()=>{i||e(void 0)}),()=>{i=!0,m.current={},a(void 0),f(!1),o(void 0),l(void 0);const e=p.current;if(void 0!==e){try{window.hcaptcha?.remove(e)}catch{}p.current=void 0}}},[R]),""===R||"pending"===R?null:(0,d.jsx)("div",{ref:h,"aria-hidden":!0,style:{position:"absolute",width:0,height:0,overflow:"hidden"},"data-client-attestation":"hcaptcha-invisible"})}export{l as t};