import{o as e}from"./rolldown-runtime.js";import{n as t,t as n}from"./jsx-runtime.js";import{Mt as r,j as i}from"./useActiveWallet-CEs8euQ3.js";import{k as a}from"./context-Cdw68BC2.js";import{C as o}from"./index-CKYEOQWW.js";import{i as s,n as c,r as l,t as u}from"./to-ui-error-84asheVg.js";var d=n(),f=e(t(),1);i();var p=({onClose:e})=>{let{user:t}=r(),n=a(),i=(0,f.useMemo)((()=>t?.mfaMethods.filter((e=>e!==`passkey`||!n.globalDisablePasskeys))??[]),[t?.mfaMethods,n.globalDisablePasskeys]),[p,m]=(0,f.useState)(i[0]??null),{init:h,cancel:g,submit:_}=o(),[v,y]=(0,f.useState)(!1),[b,x]=(0,f.useState)(null),[S,C]=(0,f.useState)();(0,f.useEffect)((()=>{m(i[0]??null)}),[i]);let w=(0,f.useRef)(!1);async function T(t){C(void 0);try{if(!t||!p)return;await _(p,t),y(!0),C(void 0),e()}catch(e){throw l(e).error}}async function E(t){if(t!==`passkey`)try{m(t),await h(t)}catch(e){console.error(e)}else try{m(t);let n=await h(t);if(!n)throw Error(`something went wrong`);x(n),await _(t,n),y(!0),C(void 0),e()}catch(e){C(l(e))}}(0,f.useEffect)((()=>{!w.current&&p&&(w.current=!0,E(p).finally((()=>{w.current=!1})))}),[]);let D=()=>{m(null),C(void 0),g(),e()};return t?p===`passkey`?(0,d.jsx)(u,{account:t.linkedAccounts.filter((e=>e.type===`passkey`&&e.enrolledInMfa)).sort(((e,t)=>t.firstVerifiedAt.valueOf()-e.firstVerifiedAt.valueOf()))[0],submitSuccess:v,hasBlockingError:S?.isBlocking??!1,error:S?.error,onClose:D,onBack:()=>{m(null),C(void 0)},handleSubmit:()=>T(b).catch(C)}):p?(0,d.jsx)(c,{submitSuccess:v,hasBlockingError:S?.isBlocking??!1,handleSubmitCode:T,selectedMethod:p,onClose:D,onBack:i.length>1?()=>m(null):void 0}):(0,d.jsx)(s,{mfaMethods:i,onSelect:E,handleClose:D}):null};export{p as MfaVerifyFlowScreen,p as default};