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,y as a}from"./useActiveWallet-CEs8euQ3.js";import{k as o}from"./context-Cdw68BC2.js";import"./index-CKYEOQWW.js";import{t as s}from"./modal-context-DHfp-mFQ.js";import{f as c,l,o as u,r as d}from"./ModalHeader-BS54PZSj.js";import{i as ee,n as f,r as p,t as m}from"./EnrollTotp-BIwTI_7R.js";import{d as h,f as g,m as _,p as v,s as y,v as b}from"./PinInput-YqT0dSuH.js";import{t as x}from"./ShieldCheckIcon.js";import{n as S}from"./QrCode-BVnyWVuE.js";var C=n(),w=e(t(),1);i(),S();var T={component:()=>{let{user:e,ready:t}=r(),{data:n,onUserCloseViaDialogOrKeybindRef:i}=s(),S=o(),[T,E]=(0,w.useState)(null),[D,O]=(0,w.useState)(null),[k,A]=(0,w.useState)(null),[j,M]=(0,w.useState)(!1),[N,P]=(0,w.useState)(!1),[F,I]=(0,w.useState)(),L=async()=>{F?R(F):e?await z({user:e}):R(Error(`Must be logged in to manage MFA`)),setTimeout((()=>{E(null),O(null)}),500)};if(i.current=L,!n?.mfaEnroll)throw Error(`Missing modal data for MFA enrollment screen.`);let{onFailure:R,onSuccess:z,onBack:B,mfaMethods:V,verify:H,generateTotpSecret:U,enrollTotp:W,unenrollTotp:G,enrollPasskey:K}=n.mfaEnroll,q=e?.mfaMethods.includes(`sms`),J=e?.mfaMethods.includes(`totp`),Y=e?.mfaMethods.includes(`passkey`),X=!!e?.phone,Z=e?.linkedAccounts.filter((e=>e.type===`passkey`)).map((e=>e.credentialId))??[];function Q(){E(null),O(null),I(void 0)}async function $(e=Z){try{I(void 0),P(!0);let t=await K(e);return await z({user:t})}catch(e){I(e)}finally{P(!1),M(!1)}}if(!t||!e||!S)return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(d,{onClose:L,backFn:B},`header`),(0,C.jsx)(v,{children:(0,C.jsx)(p,{})}),(0,C.jsx)(_,{children:(0,C.jsx)(a,{})}),(0,C.jsx)(u,{})]});if(T===`sms`)return null;if(T===`totp`)return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(d,{backFn:Q,onClose:L},`header`),(0,C.jsx)(b,{style:{marginBottom:`1.5rem`},children:(0,C.jsx)(c,{})}),(0,C.jsx)(h,{children:`Remove authenticator app verification?`}),(0,C.jsxs)(y,{children:[`MFA adds an extra layer of security to your `,S?.name,` account. Make sure you have other methods to secure your account.`]}),(0,C.jsx)(g,{children:(0,C.jsx)(l,{$warn:!0,onClick:async function(){try{I(void 0),P(!0);let e=await G();return await z({user:e})}catch(e){I(e)}finally{P(!1),E(null)}},loading:N,children:`Remove`})}),(0,C.jsx)(u,{})]});if(T===`passkey`){let e=n.mfaEnroll.shouldUnlinkOnUnenrollMfa??!0;return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(d,{backFn:Q,onClose:L},`header`),(0,C.jsx)(b,{style:{marginBottom:`1.5rem`},children:(0,C.jsx)(c,{})}),(0,C.jsx)(h,{children:`Are you sure you want to remove this passkey?`}),(0,C.jsx)(y,{children:e?`Removing your passkey will remove as both a verification method and a login method.`:`Removing your passkey will remove as a verification method.`}),(0,C.jsx)(g,{children:(0,C.jsx)(l,{$warn:!0,onClick:async function(){try{I(void 0),P(!0);let e=await K([]);return await z({user:e})}catch(e){I(e)}finally{P(!1),E(null)}},loading:N,children:`Remove`})}),(0,C.jsx)(u,{})]})}return V.length!==0||q||J||Y?D===`sms`?null:D===`totp`&&k?(0,C.jsx)(ee,{onClose:L,onReset:Q,submitEnrollmentWithTotp:e=>async function(e){try{I(void 0),P(!0);let t=await W(e);return await z({user:t})}catch(e){I(e)}finally{P(!1),E(null)}}(e.mfaCode),error:F,totpInfo:{...k,appName:S?.name||`Privy`}}):D===`passkey`?(0,C.jsx)(f,{onReset:Q,onClose:L,submitEnrollmentWithPasskey:$}):(0,C.jsx)(m,{showIntro:!0,userMfaMethods:e.mfaMethods,appMfaMethods:S.mfa.methods,userHasAuthSms:X,backFn:B,handleSelectMethod:async function(e){I(void 0);try{await H()}catch(e){I(e);return}return e===`totp`?(O(e),A(null),void U().then((({totpSecret:e,totpAuthUrl:t})=>{A({authUrl:t,secret:e})})).catch((()=>{A(null),Q()}))):e===`passkey`&&Z.length===1?await $():void O(e)},isTotpLoading:D===`totp`&&!k,isPasskeyLoading:j,error:F,onClose:L,setRemovingMfaMethod:async function(e){I(void 0);try{await H()}catch(e){I(e);return}E(e)}}):(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(d,{onClose:L,backFn:B},`header`),(0,C.jsx)(b,{style:{marginBottom:`1.5rem`},children:(0,C.jsx)(x,{})}),(0,C.jsx)(h,{children:`Add more security`}),(0,C.jsxs)(y,{children:[S?.name,` does not have any verification methods enabled.`]}),(0,C.jsx)(g,{children:(0,C.jsx)(l,{onClick:L,children:`Close`})}),(0,C.jsx)(u,{})]})}};export{T as MfaAuthEnrollmentFlowScreen,T as default};