import{o as e}from"./rolldown-runtime.js";import{n as t,t as n}from"./jsx-runtime.js";import{Mt as r,St as i,T as a,Vt as o,_t as s,j as c}from"./useActiveWallet-CEs8euQ3.js";import{b as l,k as u}from"./context-Cdw68BC2.js";import"./index-CKYEOQWW.js";import{t as d}from"./modal-context-DHfp-mFQ.js";import{t as f}from"./fingerprint-pattern.js";import{t as p}from"./ScreenLayout-Dy-3vlz4.js";import{t as m}from"./shouldProceedtoEmbeddedWalletCreationFlow-Zce_uO5W.js";var h=n(),g=e(t(),1);c();var _=({status:e,passkeySignupFlow:t=!1,error:n,onRetry:r})=>(0,h.jsx)(p,{title:(()=>{switch(e){case`loading`:return`Waiting for passkey`;case`success`:return`Success`;case`error`:return`Something went wrong`}})(),subtitle:(0,h.jsx)(y,{children:(()=>{switch(e){case`loading`:return t?`Please follow prompts to register your passkey.`:`Please follow prompts to verify your passkey.
You 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(n instanceof i){if(n.privyErrorCode===s.CANNOT_LINK_MORE_OF_TYPE)return`Cannot link more passkeys to account.`;if(n.privyErrorCode===s.PASSKEY_NOT_ALLOWED)return`Passkey request timed out or rejected by user.
You will have to sign up with another method first to register a passkey for your account.`}return`An unknown error occurred.
You will have to sign up with another method first to register a passkey for your account.`}})()}),icon:f,iconVariant:`loading`,iconLoadingStatus:{success:e===`success`,fail:e===`error`},primaryCta:e===`error`&&r?{label:`Retry`,onClick:r}:e===`success`?{label:`Continue`,disabled:!0}:void 0,watermark:!0}),v={component:()=>{let{data:e,setModalData:t,navigate:n}=d(),i=u(),{loginWithPasskey:a,signupWithPasskey:c,closePrivyModal:f,createAnalyticsEvent:p}=o(),{user:v,logout:y,ready:b,authenticated:x}=r(),{passkeySignupFlow:S}=e?.passkeyAuthModalData??{},C=l-500,[w,T]=(0,g.useState)(`loading`),[E,D]=(0,g.useState)(null),O=(0,g.useRef)([]),k=e=>{O.current=[e,...O.current]};(0,g.useEffect)((()=>()=>{O.current.forEach((e=>clearTimeout(e))),O.current=[]}),[]);let A=async()=>{T(`loading`);try{S?await c():await a(),T(`success`)}catch(e){if(e?.privyErrorCode===s.USER_DOES_NOT_EXIST)return void n(`AccountNotFoundScreen`);if(e?.privyErrorCode===s.ALLOWLIST_REJECTED)return void n(`AllowlistRejectionScreen`);if(e?.privyErrorCode===s.USER_LIMIT_REACHED)return void n(`UserLimitReachedScreen`);D(e),T(`error`)}};return(0,g.useEffect)((()=>{if(b&&x&&w===`success`&&v){if(i?.legal.requireUsersAcceptTerms&&!v.hasAcceptedTerms)return void k(setTimeout((()=>{n(`AffirmativeConsentScreen`)}),C));if(!m(v,i?.embeddedWallets))return void k(setTimeout((()=>{f({shouldCallAuthOnSuccess:!0,isSuccess:!0})}),l));k(setTimeout((()=>{t({createWallet:{onSuccess:()=>{},onFailure:e=>{console.error(e),p({eventName:`embedded_wallet_creation_failure_logout`,payload:{error:e,screen:`PasskeyStatusScreen`}}),y()},callAuthOnSuccessOnClose:!0}}),n(`EmbeddedWalletOnAccountCreateScreen`)}),C))}}),[b,x,v,w]),(0,g.useEffect)((()=>{A()}),[]),(0,h.jsx)(_,{status:w,passkeySignupFlow:S,error:E,onRetry:A})}},y=a.span`
  white-space: pre-wrap;
`;export{v as PasskeyStatusScreen,v as default,_ as PasskeyStatusScreenView};