`)),t("Backup codes copied to clipboard"))},[u,t]),C=n.useCallback(()=>{if(!u?.recovery_codes)return;const p=document.createElement("a"),T=new Blob([u.recovery_codes.join(`
`)],{type:"text/plain"});p.href=URL.createObjectURL(T),p.download="veza-backup-codes.txt",document.body.appendChild(p),p.click(),t("Backup codes downloaded")},[u,t]),L=n.useCallback(()=>{d("totp"),l(2)},[]),S=n.useCallback(()=>{t("SMS method not yet available in this region","info")},[t]);return{step:r,setStep:l,method:i,verificationCode:o,setVerificationCode:x,loading:c,setupData:u,error:g,fetchSetupData:j,handleVerify:_,copyCodes:P,downloadCodes:C,goToStep2Totp:L,handleSmsUnavailable:S}}function os({onBack:s,onComplete:a}){const{addToast:t}=me(),{step:r,method:l,verificationCode:i,setVerificationCode:d,loading:o,setupData:x,handleVerify:c,copyCodes:m,downloadCodes:u,goToStep2Totp:f,handleSmsUnavailable:g}=ns(s),y=()=>{x&&(navigator.clipboard.writeText(x.secret),t("Secret Key copied"))};return e.jsxs("div",{className:"animate-fadeIn max-w-2xl mx-auto",children:[e.jsx(ss,{onBack:s}),r===1&&e.jsx(as,{onChooseTotp:f,onChooseSms:g}),r===2&&e.jsx(ts,{method:l,loading:o,setupData:x,verificationCode:i,onVerificationCodeChange:d,onVerify:c,onCopySecret:y,onSendSmsPlaceholder:()=>t("Code sent to your phone","info")}),r===3&&e.jsx(rs,{setupData:x,onCopy:m,onDownload:u,onComplete:a})]})}const ls=()=>{const[s,a]=n.useState(null),[t,r]=n.useState(!0),[l,i]=n.useState(!1),d=async()=>{r(!0);try{const o=await te.getStatus();a(o.enabled)}catch(o){Ae.error("Failed to fetch 2FA status",{error:o})}finally{r(!1)}};return n.useEffect(()=>{d()},[]),l?e.jsx(z,{className:"border-primary/20 bg-primary/5",children:e.jsx(Y,{className:"pt-6",children:e.jsx(os,{onBack:()=>i(!1),onComplete:()=>{i(!1),d()}})})}):e.jsxs(z,{children:[e.jsxs(K,{children:[e.jsxs($,{className:"flex items-center gap-2",children:[e.jsx(fe,{className:"h-5 w-5"}),"Two-Factor Authentication (2FA)"]}),e.jsx(X,{children:"Add an extra layer of security to your account"})]}),e.jsx(Y,{children:t?e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[e.jsx(ae,{className:"h-4 w-4 animate-spin"})," Checking 2FA status..."]}):s?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3 p-4 bg-success/10 border border-success/20 rounded-lg",children:[e.jsx(Ue,{className:"h-8 w-8 text-success"}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-bold text-foreground",children:"2FA is enabled"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Your account is protected by an additional security layer."})]})]}),e.jsx(N,{variant:"outline",className:"text-destructive hover:bg-destructive/10 hover:text-destructive border-destructive/20",onClick:()=>{confirm("Are you sure you want to disable 2FA? This will make your account less secure.")&&a(!1)},children:"Disable 2FA"})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3 p-4 bg-orange-500/5 border border-orange-500/10 rounded-lg",children:[e.jsx(ze,{className:"h-8 w-8 text-orange-500"}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-bold text-foreground",children:"2FA is not enabled"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"We highly recommend enabling 2FA to protect your music and assets."})]})]}),e.jsx(N,{onClick:()=>i(!0),children:"Setup 2FA"})]})})]})};function is(){const{mutationError:s,retryCount:a,maxRetry:t,handleRetry:r,dismissError:l,isChangingPassword:i,currentPassword:d,setCurrentPassword:o,newPassword:x,setNewPassword:c,confirmPassword:m,setConfirmPassword:u,passwordError:f,handleChangePassword:g,isDeleteDialogOpen:y,setIsDeleteDialogOpen:j,isDeletingAccount:_,deletePassword:P,setDeletePassword:C,deleteReason:L,setDeleteReason:S,deleteConfirmText:p,setDeleteConfirmText:T,deleteValidationError:k,setDeleteValidationError:Z,handleDeleteAccount:A,handleExportData:M}=Ke();return e.jsxs("div",{className:"space-y-6",children:[s&&e.jsx($e,{error:s,retryCount:a,maxRetry:t,onRetry:r,onDismiss:l}),e.jsx(Xe,{currentPassword:d,setCurrentPassword:o,newPassword:x,setNewPassword:c,confirmPassword:m,setConfirmPassword:u,passwordError:f,isChangingPassword:i,onSubmit:g}),e.jsx(ls,{}),e.jsx(