import{r as n,j as e}from"./react-vendor-MPLM8hiW.js";import{a as y,C,c as g,B as v,d as N,e as b,L as X,I as S,f as w,g as u,aN as k}from"./index-saDuzM6I.js";import{l as L,L as R}from"./icons-vendor-H2PpUqT3.js";function B({challengeToken:x,onCancel:f,onSuccess:p}){const{t:s}=y(),[l,c]=n.useState(""),[t,h]=n.useState(!1),[o,i]=n.useState(!1),[d,m]=n.useState(null),j=async a=>{a.preventDefault(),m(null),i(!0);try{const r=await k.verify({challengeToken:x,code:l.trim(),useRecovery:t});p(r.data.token,r.data.user)}catch(r){m(r instanceof Error?r.message:s("mfa.invalidCode"))}finally{i(!1)}};return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background p-4",children:e.jsxs(C,{className:"w-full max-w-md",children:[e.jsxs(g,{className:"space-y-1 text-center",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx(v,{size:"lg"})}),e.jsxs(N,{className:"text-xl flex items-center justify-center gap-2",children:[e.jsx(L,{className:"h-5 w-5"})," ",s("mfa.verifyTitle")]})]}),e.jsxs("form",{onSubmit:j,children:[e.jsxs(b,{className:"space-y-4",children:[d&&e.jsx("div",{className:"p-3 rounded-lg bg-error-light text-error text-sm",role:"alert",children:d}),e.jsx("p",{className:"text-sm text-text-secondary",children:s(t?"mfa.enterRecoveryCode":"mfa.enterTotpCode")}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(X,{htmlFor:"mfa-code",children:s(t?"mfa.recoveryCode":"mfa.totpCode")}),e.jsx(S,{id:"mfa-code",value:l,onChange:a=>c(a.target.value),inputMode:t?"text":"numeric",autoComplete:"one-time-code",placeholder:t?"XXXXX-XXXXX":"000000",autoFocus:!0})]}),e.jsx("button",{type:"button",className:"text-xs text-primary hover:underline",onClick:()=>{h(a=>!a),c("")},children:s(t?"mfa.useTotpInstead":"mfa.useRecoveryInstead")})]}),e.jsxs(w,{className:"flex flex-col gap-2",children:[e.jsx(u,{type:"submit",className:"w-full",disabled:o||l.length===0,children:o?e.jsx(R,{className:"animate-spin"}):s("mfa.verifyAndContinue")}),e.jsx(u,{type:"button",variant:"ghost",className:"w-full",onClick:f,children:s("common.cancel")})]})]})]})})}export{B as M};
