import{jsx as e}from"react/jsx-runtime";import{FingerprintIcon as r}from"lucide-react";import{useState as t,useRef as o,useEffect as i}from"react";import{styled as s}from"styled-components";import{u as a,r as n}from"./context-BKnOUECq.mjs";import{b as c,a as m}from"./errors-Dd6zfYtp.mjs";import{u}from"./internal-context-dfitw7Ot.mjs";import{u as p}from"./modal-context-DBwfUxD-.mjs";import{u as l}from"./privy-context-Bi6vqCPc.mjs";import{s as d}from"./shouldProceedtoEmbeddedWalletCreationFlow-SyjOJUom.mjs";import{S as y}from"./ScreenLayout-Caq5mGD8.mjs";import"@privy-io/js-sdk-core";import"tinycolor2";import"ofetch";import"@privy-io/are-addresses-equal";import"./index-C5jxD-zy.mjs";import"./toViemAccount-4iGGrW4w.mjs";import"jose";import"eventemitter3";import"./index-BtwxknTg.mjs";import"zustand";import"viem";import"viem/utils";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"./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 f=({status:t,passkeySignupFlow:o=!1,error:i,onRetry:s})=>/*#__PURE__*/e(y,{title:(()=>{switch(t){case"loading":return"Waiting for passkey";case"success":return"Success";case"error":return"Something went wrong"}})(),subtitle:/*#__PURE__*/e(v,{children:(()=>{switch(t){case"loading":return o?"Please follow prompts to register your passkey.":"Please follow prompts to verify your passkey.\nYou will have to sign up with another method first to register a passkey for your account.";case"success":return"You've successfully logged in with your passkey.";case"error":if(i instanceof c){if(i.privyErrorCode===m.CANNOT_LINK_MORE_OF_TYPE)return"Cannot link more passkeys to account.";if(i.privyErrorCode===m.PASSKEY_NOT_ALLOWED)return"Passkey request timed out or rejected by user.\nYou will have to sign up with another method first to register a passkey for your account."}return"An unknown error occurred.\nYou will have to sign up with another method first to register a passkey for your account."}})()}),icon:r,iconVariant:"loading",iconLoadingStatus:{success:"success"===t,fail:"error"===t},primaryCta:"error"===t&&s?{label:"Retry",onClick:s}:"success"===t?{label:"Continue",disabled:!0}:void 0,watermark:!0}),h={component:()=>{let{data:r,setModalData:s,navigate:c}=p(),y=a(),{loginWithPasskey:h,signupWithPasskey:v,closePrivyModal:g,createAnalyticsEvent:j}=u(),{user:w,logout:k,ready:S,authenticated:E}=l(),{passkeySignupFlow:C}=r?.passkeyAuthModalData??{},A=n-500,[b,_]=t("loading"),[T,P]=t(null),x=o([]),O=e=>{x.current=[e,...x.current]};i((()=>()=>{x.current.forEach((e=>clearTimeout(e))),x.current=[]}),[]);let L=async()=>{_("loading");try{C?await v():await h(),_("success")}catch(e){if(e?.privyErrorCode===m.USER_DOES_NOT_EXIST)return void c("AccountNotFoundScreen");if(e?.privyErrorCode===m.ALLOWLIST_REJECTED)return void c("AllowlistRejectionScreen");if(e?.privyErrorCode===m.USER_LIMIT_REACHED)return void c("UserLimitReachedScreen");P(e),_("error")}};return i((()=>{if(S&&E&&"success"===b&&w){if(y?.legal.requireUsersAcceptTerms&&!w.hasAcceptedTerms)return void O(setTimeout((()=>{c("AffirmativeConsentScreen")}),A));if(!d(w,y?.embeddedWallets))return void O(setTimeout((()=>{g({shouldCallAuthOnSuccess:!0,isSuccess:!0})}),n));O(setTimeout((()=>{s({createWallet:{onSuccess:()=>{},onFailure:e=>{console.error(e),j({eventName:"embedded_wallet_creation_failure_logout",payload:{error:e,screen:"PasskeyStatusScreen"}}),k()},callAuthOnSuccessOnClose:!0}}),c("EmbeddedWalletOnAccountCreateScreen")}),A))}}),[S,E,w,b]),i((()=>{L()}),[]),/*#__PURE__*/e(f,{status:b,passkeySignupFlow:C,error:T,onRetry:L})}};let v=s.span`
  white-space: pre-wrap;
`;export{h as PasskeyStatusScreen,f as PasskeyStatusScreenView,h as default};
//# sourceMappingURL=PasskeyStatusScreen-B0gRhyUf.mjs.map
