import{jsx as e}from"react/jsx-runtime";import{CheckCircle as t,XCircle as r}from"lucide-react";import{useRef as i,useState as o,useEffect as s,useMemo as a}from"react";import{a as n,C as m}from"./index-C5jxD-zy.mjs";import{u as c}from"./modal-context-DBwfUxD-.mjs";import{S as u}from"./ScreenLayout-Caq5mGD8.mjs";import"@privy-io/js-sdk-core";import"./toViemAccount-4iGGrW4w.mjs";import"jose";import"./privy-context-Bi6vqCPc.mjs";import"@privy-io/are-addresses-equal";import"./internal-context-dfitw7Ot.mjs";import"eventemitter3";import"./index-BtwxknTg.mjs";import"zustand";import"./context-BKnOUECq.mjs";import"tinycolor2";import"viem";import"viem/utils";import"./errors-Dd6zfYtp.mjs";import"ofetch";import"./wallet-connect-58EobR5U.mjs";import"./getPublicClient-D4yNgeGy.mjs";import"viem/chains";import"react-device-detect";import"@coinbase/wallet-sdk";import"@walletconnect/ethereum-provider";import"./pkce-BinverJO.mjs";import"./paths-BH8W4zMc.mjs";import"./PrivyPluginContext-DA-yS5vO.mjs";import"js-cookie";import"@privy-io/ethereum";import"viem/accounts";import"mipd";import"@scure/base";import"./usePrivy-BhL-ltvm.mjs";import"./use-unlink-wallet-oAguM2-k.mjs";import"./get-entropy-details-for-user-BIWg0YxF.mjs";import"./user-D5cqJNp9.mjs";import"@privy-io/popup";import"./events-context-BJ75xIIf.mjs";import"styled-components";import"./useActiveWallet-BEfvREjE.mjs";import"@headlessui/react";import"@privy-io/urls";import"./getEmbeddedConnectedWallet-Ba6LFHzY.mjs";import"./frame-DtizlaLu.mjs";import"@privy-io/routes";import"./use-deposit-address-BwThybOQ.mjs";import"x402/client";import"@privy-io/api-base";import"./use-sign-with-user-signer-CQI6hUH7.mjs";import"./ModalHeader-DffkxvO4.mjs";import"@heroicons/react/24/outline/ArrowLeftIcon";import"@heroicons/react/24/outline/ArrowRightIcon";import"@heroicons/react/24/outline/QuestionMarkCircleIcon";import"@heroicons/react/24/outline/XMarkIcon";import"./Screen-D8KNyGVj.mjs";import"./index-Dq_xe9dz.mjs";const p=({status:i,title:o,description:s,userIntentRequired:n,retriesRemaining:m,hasSelectedCta:c,onContinue:p,onRetry:l})=>{let d=a((()=>{switch(i){case"loading":default:return;case"success":return n?{label:c?"Continuing...":"Continue",onClick:p,disabled:c,loading:c}:void 0;case"error":return m>0?{label:"Retry",onClick:l}:void 0}}),[i,c,p,l]),j=a((()=>({loading:"loading",ready:"subtle",disabled:"subtle",success:"success",error:"error"}[i]||"loading")),[i]);/*#__PURE__*/return e(u,{icon:"loading"===i||"ready"===i?void 0:"success"===i?t:r,iconVariant:j,title:o,subtitle:s,primaryCta:d,watermark:!0})},l={component:()=>{let{lastScreen:t,data:r,navigate:a,setModalData:u}=c(),{status:l,token:d,waitForResult:j,reset:y,execute:g}=n(),h=i([]),v=e=>{h.current=[e,...h.current]},[f,C]=o(!0);s((()=>(v(setTimeout(C,1e3,!1)),()=>{h.current.forEach((e=>clearTimeout(e))),h.current=[]})),[]);let[b,k]=o(""),[w,S]=o("Checking that you are a human..."),[x,R]=o(!1),[I,T]=o(3),q=r?.captchaModalData,A=async e=>{try{await(q?.callback(e)),q?.onSuccessNavigateTo&&a(q?.onSuccessNavigateTo,!1)}catch(e){if(e instanceof m)return;u({errorModalData:{error:e,previousScreen:t||"LandingScreen"}}),a(q?.onErrorNavigateTo||"ErrorScreen",!1)}};s((()=>{"success"===l?v(setTimeout((async()=>{let e=await j();!e||q?.userIntentRequired||A(e)}),1e3)):"ready"===l&&v(setTimeout((()=>{"ready"===l&&g()}),500))}),[l]),s((()=>{if(!f)switch(l){case"success":k("Success!"),S("CAPTCHA passed successfully."),q?.userIntentRequired||setTimeout((()=>{R(!0),A(d)}),2e3);break;case"loading":k(""),S("Checking that you are a human...");break;case"error":k("Something went wrong"),S(I<=0?"If you use an adblocker or VPN, try disabling and re-attempting.":"You did not pass CAPTCHA. Please try again.")}}),[l,f,x]);/*#__PURE__*/return e(p,{status:l,title:b,description:w,userIntentRequired:q?.userIntentRequired,retriesRemaining:I,hasSelectedCta:x,onContinue:()=>{R(!0),A(d)},onRetry:async()=>{if(I<=0)return;T((e=>e-1)),y(),g();let e=await j();!e||q?.userIntentRequired||A(e)}})}};export{l as CaptchaScreen,p as CaptchaScreenView,l as default};
//# sourceMappingURL=CaptchaScreen-knKoZcB2.mjs.map
