import{o as e}from"./rolldown-runtime.js";import{n as t,t as n}from"./jsx-runtime.js";import{j as r}from"./useActiveWallet-CEs8euQ3.js";import"./context-Cdw68BC2.js";import{d as i,t as a}from"./index-CKYEOQWW.js";import{t as o}from"./modal-context-DHfp-mFQ.js";import{t as s}from"./circle-check-big.js";import{t as c}from"./circle-x.js";import{t as l}from"./ScreenLayout-Dy-3vlz4.js";var u=n(),d=e(t(),1);r();var f=({status:e,title:t,description:n,userIntentRequired:r,retriesRemaining:i,hasSelectedCta:a,onContinue:o,onRetry:f})=>{let p=(0,d.useMemo)((()=>{switch(e){case`loading`:default:return;case`success`:return r?{label:a?`Continuing...`:`Continue`,onClick:o,disabled:a,loading:a}:void 0;case`error`:return i>0?{label:`Retry`,onClick:f}:void 0}}),[e,a,o,f]),m=(0,d.useMemo)((()=>({loading:`loading`,ready:`subtle`,disabled:`subtle`,success:`success`,error:`error`})[e]||`loading`),[e]);return(0,u.jsx)(l,{icon:e===`loading`||e===`ready`?void 0:e===`success`?s:c,iconVariant:m,title:t,subtitle:n,primaryCta:p,watermark:!0})},p={component:()=>{let{lastScreen:e,data:t,navigate:n,setModalData:r}=o(),{status:s,token:c,waitForResult:l,reset:p,execute:m}=a(),h=(0,d.useRef)([]),g=e=>{h.current=[e,...h.current]},[_,v]=(0,d.useState)(!0);(0,d.useEffect)((()=>(g(setTimeout(v,1e3,!1)),()=>{h.current.forEach((e=>clearTimeout(e))),h.current=[]})),[]);let[y,b]=(0,d.useState)(``),[x,S]=(0,d.useState)(`Checking that you are a human...`),[C,w]=(0,d.useState)(!1),[T,E]=(0,d.useState)(3),D=t?.captchaModalData,O=async t=>{try{await D?.callback(t),D?.onSuccessNavigateTo&&n(D?.onSuccessNavigateTo,!1)}catch(t){if(t instanceof i)return;r({errorModalData:{error:t,previousScreen:e||`LandingScreen`}}),n(D?.onErrorNavigateTo||`ErrorScreen`,!1)}};return(0,d.useEffect)((()=>{s===`success`?g(setTimeout((async()=>{let e=await l();!e||D?.userIntentRequired||O(e)}),1e3)):s===`ready`&&g(setTimeout((()=>{s===`ready`&&m()}),500))}),[s]),(0,d.useEffect)((()=>{if(!_)switch(s){case`success`:b(`Success!`),S(`CAPTCHA passed successfully.`),D?.userIntentRequired||setTimeout((()=>{w(!0),O(c)}),2e3);break;case`loading`:b(``),S(`Checking that you are a human...`);break;case`error`:b(`Something went wrong`),S(T<=0?`If you use an adblocker or VPN, try disabling and re-attempting.`:`You did not pass CAPTCHA. Please try again.`)}}),[s,_,C]),(0,u.jsx)(f,{status:s,title:y,description:x,userIntentRequired:D?.userIntentRequired,retriesRemaining:T,hasSelectedCta:C,onContinue:()=>{w(!0),O(c)},onRetry:async()=>{if(T<=0)return;E((e=>e-1)),p(),m();let e=await l();!e||D?.userIntentRequired||O(e)}})}};export{p as CaptchaScreen,p as default,f as CaptchaScreenView};