3 lines
34 KiB
JavaScript
3 lines
34 KiB
JavaScript
import{a as n,j as e}from"./vendor-react-YMhRUmcb.js";import{d as de,h as Ce,g as Se,p as Z,a as P,E as B,C as q,b as K,c as W,f as $,e as H,B as b,D as ke,m as ue,S as re,u as _e,L as J,t as ne}from"./index-D2uzyr9g.js";import{u as oe}from"./users-DDt25V_U.js";import{T as Ae,a as Ee,b as M,c as U}from"./Tabs-C8UCeQNW.js";import{L as d,I as A}from"./input-DL1WY4HG.js";import{S as ee}from"./Select-So_RP28r.js";import{ak as Te,ar as Fe,A as me,al as se,T as le,as as De,at as Re,au as he,g as ae,d as xe,a as Pe,C as Le,O as pe,av as qe,aw as Ve,ax as Ie,ay as ze}from"./vendor-icons-DINCNwpk.js";import{C as w}from"./checkbox-Cwr-kRad.js";import{A as fe,a as ge}from"./alert-COAUu9KR.js";import{r as Q}from"./features-CKIBrJL0.js";import{o as O,e as ie,s as Me,b as y}from"./vendor-utils-4BWoYre8.js";import"./vendor-fFnFILYR.js";import"./vendor-router-DX94Iu-2.js";import"./vendor-tanstack-CoFNL2zy.js";import"./dropdown-DLDDI8f2.js";const je=n.forwardRef(({className:s,value:t,onValueChange:a,disabled:r,children:i,...l},c)=>e.jsx("div",{ref:c,className:de("grid gap-2",s),role:"radiogroup",...l,children:n.Children.map(i,o=>n.isValidElement(o)&&o.type===G?n.cloneElement(o,{checked:o.props.value===t,onCheckedChange:()=>a?.(o.props.value),disabled:r||o.props.disabled}):o)}));je.displayName="RadioGroup";const G=n.forwardRef(({className:s,value:t,checked:a,onCheckedChange:r,disabled:i,...l},c)=>e.jsxs("label",{className:de("aspect-square h-4 w-4 rounded-full border border-kodo-steel text-kodo-steel","ring-offset-kodo-void focus-within:outline-none focus-within:ring-2 focus-within:ring-kodo-steel focus-within:ring-offset-2","disabled:cursor-not-allowed disabled:opacity-50","cursor-pointer relative inline-flex items-center justify-center",a&&"border-kodo-steel",s),children:[e.jsx("input",{ref:c,type:"radio",value:t,checked:a,onChange:r,disabled:i,className:"sr-only",...l}),a&&e.jsx(Te,{className:"h-2.5 w-2.5 fill-current text-current"})]}));G.displayName="RadioGroupItem";const Ue=[{value:"en",label:"English"},{value:"fr",label:"Français"},{value:"es",label:"Español"},{value:"de",label:"Deutsch"},{value:"it",label:"Italiano"},{value:"pt",label:"Português"},{value:"ru",label:"Русский"},{value:"ja",label:"日本語"},{value:"zh",label:"中文"},{value:"ko",label:"한국어"}],Oe=[{value:"UTC",label:"UTC"},{value:"Europe/Paris",label:"Europe/Paris"},{value:"America/New_York",label:"America/New_York"},{value:"America/Los_Angeles",label:"America/Los_Angeles"},{value:"Asia/Tokyo",label:"Asia/Tokyo"},{value:"Asia/Shanghai",label:"Asia/Shanghai"}];function Ge({preferences:s,onChange:t}){const a=l=>{t({...s,language:Array.isArray(l)?l[0]:l})},r=l=>{t({...s,timezone:Array.isArray(l)?l[0]:l})},i=l=>{t({...s,theme:l})};return e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"language",children:"Langue"}),e.jsx(ee,{options:Ue,value:s.language,onChange:a,placeholder:"Sélectionner une langue",name:"language"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"timezone",children:"Fuseau horaire"}),e.jsx(ee,{options:Oe,value:s.timezone,onChange:r,placeholder:"Sélectionner un fuseau horaire",name:"timezone"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{children:"Thème"}),e.jsxs(je,{value:s.theme,onValueChange:i,children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(G,{value:"light",id:"theme-light"}),e.jsx(d,{htmlFor:"theme-light",className:"font-normal",children:"Clair"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(G,{value:"dark",id:"theme-dark"}),e.jsx(d,{htmlFor:"theme-dark",className:"font-normal",children:"Sombre"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(G,{value:"auto",id:"theme-auto"}),e.jsx(d,{htmlFor:"theme-auto",className:"font-normal",children:"Automatique"})]})]})]})]})})}function He({notifications:s,onChange:t}){const a=(r,i)=>{t({...s,[r]:i})};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Notifications par email"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(d,{htmlFor:"email_notifications",children:"Notifications email"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Recevoir des notifications par email"})]}),e.jsx(w,{id:"email_notifications",checked:s.email_notifications,onCheckedChange:r=>a("email_notifications",r===!0)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(d,{htmlFor:"push_notifications",children:"Notifications push"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Recevoir des notifications push"})]}),e.jsx(w,{id:"push_notifications",checked:s.push_notifications,onCheckedChange:r=>a("push_notifications",r===!0)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(d,{htmlFor:"browser_notifications",children:"Notifications navigateur"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Recevoir des notifications dans le navigateur"})]}),e.jsx(w,{id:"browser_notifications",checked:s.browser_notifications,onCheckedChange:r=>a("browser_notifications",r===!0)})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Notifications d'activité"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(d,{htmlFor:"email_on_follow",children:"Email lors d'un follow"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Recevoir un email quand quelqu'un vous suit"})]}),e.jsx(w,{id:"email_on_follow",checked:s.email_on_follow,onCheckedChange:r=>a("email_on_follow",r===!0)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(d,{htmlFor:"email_on_like",children:"Email lors d'un like"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Recevoir un email quand quelqu'un aime votre contenu"})]}),e.jsx(w,{id:"email_on_like",checked:s.email_on_like,onCheckedChange:r=>a("email_on_like",r===!0)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(d,{htmlFor:"email_on_comment",children:"Email lors d'un commentaire"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Recevoir un email quand quelqu'un commente votre contenu"})]}),e.jsx(w,{id:"email_on_comment",checked:s.email_on_comment,onCheckedChange:r=>a("email_on_comment",r===!0)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(d,{htmlFor:"email_on_message",children:"Email lors d'un message"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Recevoir un email quand vous recevez un message"})]}),e.jsx(w,{id:"email_on_message",checked:s.email_on_message,onCheckedChange:r=>a("email_on_message",r===!0)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(d,{htmlFor:"email_on_mention",children:"Email lors d'une mention"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Recevoir un email quand quelqu'un vous mentionne"})]}),e.jsx(w,{id:"email_on_mention",checked:s.email_on_mention,onCheckedChange:r=>a("email_on_mention",r===!0)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(d,{htmlFor:"email_marketing",children:"Email marketing"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Recevoir des emails promotionnels et des actualités"})]}),e.jsx(w,{id:"email_marketing",checked:s.email_marketing,onCheckedChange:r=>a("email_marketing",r===!0)})]})]})]})]})}function Ye({privacy:s,onChange:t}){const a=(r,i)=>{t({...s,[r]:i})};return e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(d,{htmlFor:"allow_search_indexing",children:"Autoriser l'indexation par les moteurs de recherche"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Permettre aux moteurs de recherche d'indexer votre profil"})]}),e.jsx(w,{id:"allow_search_indexing",checked:s.allow_search_indexing,onCheckedChange:r=>a("allow_search_indexing",r===!0)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(d,{htmlFor:"show_activity",children:"Afficher l'activité"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Permettre aux autres utilisateurs de voir votre activité"})]}),e.jsx(w,{id:"show_activity",checked:s.show_activity,onCheckedChange:r=>a("show_activity",r===!0)})]})]})})}const ce=3;function Qe(){const{logout:s}=Ce(),t=Se(),[a,r]=n.useState(!1),[i,l]=n.useState(!1),[c,o]=n.useState(!1),[h,u]=n.useState(""),[x,m]=n.useState(""),[p,f]=n.useState(""),[j,v]=n.useState(""),[k,g]=n.useState(""),[N,C]=n.useState(""),[E,S]=n.useState(""),[V,I]=n.useState(null),[X,_]=n.useState(null),[z,Y]=n.useState(0),R=n.useRef(null),ye=n.useCallback(async T=>{if(T.preventDefault(),v(""),x!==p){v("New passwords do not match");return}if(x.length<12){v("Password must be at least 12 characters long");return}const F=async()=>{await P.put("/users/me/password",{current_password:h,new_password:x}),t.success("Password changed successfully"),u(""),m(""),f(""),_(null),Y(0),R.current=null};R.current=F,r(!0);try{await F()}catch(L){const D=Z(L);v(D.message),_(new Error(D.message))}finally{r(!1)}},[h,x,p,t]),ve=n.useCallback(async()=>{if(I(null),_(null),E!=="DELETE"){I("Please type DELETE to confirm");return}try{l(!0),await P.delete("/users/me",{data:{password:k,reason:N,confirm_text:E}}),t.success("Account deletion requested. You will be logged out."),setTimeout(()=>{s(),window.location.href="/login"},2e3)}catch(T){const F=Z(T);_(new Error(F.message))}finally{l(!1),o(!1)}},[k,N,E,t,s]),we=n.useCallback(async()=>{const T=async()=>{const F=await P.get("/users/me/export",{responseType:"blob"}),L=window.URL.createObjectURL(new Blob([F.data])),D=document.createElement("a");D.href=L,D.setAttribute("download",`veza-data-export-${new Date().toISOString()}.json`),document.body.appendChild(D),D.click(),D.remove(),window.URL.revokeObjectURL(L),t.success("Data export started"),_(null),Y(0),R.current=null};R.current=T;try{await T()}catch(F){const L=Z(F);_(new Error(L.message))}},[t]),be=n.useCallback(async()=>{if(!(!R.current||z>=ce)){Y(T=>T+1);try{await R.current()}catch{}}},[z]),Ne=n.useCallback(()=>{_(null),Y(0),R.current=null},[]);return{mutationError:X,retryCount:z,maxRetry:ce,handleRetry:be,dismissError:Ne,isChangingPassword:a,currentPassword:h,setCurrentPassword:u,newPassword:x,setNewPassword:m,confirmPassword:p,setConfirmPassword:f,passwordError:j,handleChangePassword:ye,isDeleteDialogOpen:c,setIsDeleteDialogOpen:o,isDeletingAccount:i,deletePassword:k,setDeletePassword:g,deleteReason:N,setDeleteReason:C,deleteConfirmText:E,setDeleteConfirmText:S,deleteValidationError:V,setDeleteValidationError:I,handleDeleteAccount:ve,handleExportData:we}}function Be({error:s,retryCount:t,maxRetry:a,onRetry:r,onDismiss:i}){return e.jsx(B,{error:s,variant:"banner",severity:"error",context:{action:"updating account settings",resource:"account"},onRetry:t<a?r:void 0,onDismiss:i})}function Ke({currentPassword:s,setCurrentPassword:t,newPassword:a,setNewPassword:r,confirmPassword:i,setConfirmPassword:l,passwordError:c,isChangingPassword:o,onSubmit:h}){return e.jsxs(q,{children:[e.jsxs(K,{children:[e.jsxs(W,{className:"flex items-center gap-2",children:[e.jsx(Fe,{className:"h-5 w-5"}),"Change Password"]}),e.jsx($,{children:"Update your password to keep your account secure"})]}),e.jsx(H,{children:e.jsxs("form",{onSubmit:h,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"current-password",children:"Current Password"}),e.jsx(A,{id:"current-password",type:"password",value:s,onChange:u=>t(u.target.value),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"new-password",children:"New Password"}),e.jsx(A,{id:"new-password",type:"password",value:a,onChange:u=>r(u.target.value),required:!0,minLength:12}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Password must be at least 12 characters long"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"confirm-password",children:"Confirm New Password"}),e.jsx(A,{id:"confirm-password",type:"password",value:i,onChange:u=>l(u.target.value),required:!0,minLength:12})]}),c&&e.jsxs(fe,{variant:"destructive",children:[e.jsx(me,{className:"h-4 w-4"}),e.jsx(ge,{children:c})]}),e.jsx(b,{type:"submit",disabled:o,children:o?"Changing...":"Change Password"})]})})]})}function We({onExport:s}){return e.jsxs(q,{children:[e.jsxs(K,{children:[e.jsxs(W,{className:"flex items-center gap-2",children:[e.jsx(se,{className:"h-5 w-5"}),"Data Export"]}),e.jsx($,{children:"Download a copy of your data (GDPR)"})]}),e.jsx(H,{children:e.jsxs(b,{variant:"outline",onClick:s,children:[e.jsx(se,{className:"mr-2 h-4 w-4"}),"Export My Data"]})})]})}function $e({isDeleteDialogOpen:s,setIsDeleteDialogOpen:t,isDeletingAccount:a,deletePassword:r,setDeletePassword:i,deleteReason:l,setDeleteReason:c,deleteConfirmText:o,setDeleteConfirmText:h,deleteValidationError:u,setDeleteValidationError:x,onDeleteAccount:m}){return e.jsxs(q,{className:"border-destructive",children:[e.jsxs(K,{children:[e.jsxs(W,{className:"flex items-center gap-2 text-destructive",children:[e.jsx(le,{className:"h-5 w-5"}),"Delete Account"]}),e.jsx($,{children:"Permanently delete your account and all associated data"})]}),e.jsxs(H,{children:[e.jsxs(fe,{variant:"destructive",children:[e.jsx(me,{className:"h-4 w-4"}),e.jsx(ge,{children:"This action cannot be undone. All your data will be permanently deleted."})]}),e.jsx(ke,{open:s,onClose:()=>t(!1),title:"Are you absolutely sure?",variant:"alert",onConfirm:m,confirmLabel:a?"Deleting...":"Delete Account",cancelLabel:"Cancel",size:"lg",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"This will permanently delete your account and all associated data. This action cannot be undone."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"delete-password",children:"Enter your password"}),e.jsx(A,{id:"delete-password",type:"password",value:r,onChange:p=>i(p.target.value),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"delete-reason",children:"Reason (optional)"}),e.jsx(A,{id:"delete-reason",value:l,onChange:p=>c(p.target.value),placeholder:"Why are you deleting your account?"})]}),u&&e.jsx(B,{error:u,variant:"inline",severity:"error",size:"sm",dismissible:!1}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(d,{htmlFor:"delete-confirm",children:["Type ",e.jsx("strong",{children:"DELETE"})," to confirm"]}),e.jsx(A,{id:"delete-confirm",value:o,onChange:p=>{h(p.target.value),x(null)},required:!0,placeholder:"DELETE"})]})]})}),e.jsxs(b,{variant:"destructive",className:"mt-4",onClick:()=>t(!0),children:[e.jsx(le,{className:"mr-2 h-4 w-4"}),"Delete Account"]})]})]})}class Xe{async getStatus(){return Q("TWO_FACTOR_AUTH"),(await P.get("/auth/2fa/status")).data}async setup(){return Q("TWO_FACTOR_AUTH"),(await P.post("/auth/2fa/setup")).data}async verify(t,a){Q("TWO_FACTOR_AUTH"),await P.post("/auth/2fa/verify",{secret:t,code:a})}async disable(t){Q("TWO_FACTOR_AUTH"),await P.post("/auth/2fa/disable",{password:t})}}const te=new Xe;function Ze({onBack:s}){return e.jsxs("div",{className:"mb-6 flex items-center gap-4",children:[e.jsx("button",{type:"button",onClick:s,className:"p-2 hover:bg-muted rounded-full text-muted-foreground hover:text-foreground transition-colors duration-[var(--duration-normal)]","aria-label":"Go back",children:e.jsx(De,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold text-foreground tracking-tight",children:"Enable Two-Factor Authentication"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Protect your account with an extra layer of security."})]})]})}function Je({onChooseTotp:s,onChooseSms:t}){return e.jsxs("div",{className:"grid gap-4",children:[e.jsx("div",{role:"button",tabIndex:0,onClick:s,onKeyDown:a=>a.key==="Enter"&&s(),className:"p-6 border border-border rounded-xl bg-card hover:bg-muted/50 cursor-pointer transition-all duration-[var(--duration-normal)] hover:border-primary/50 group",children:e.jsxs("div",{className:"flex items-center gap-4 mb-2",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-muted flex items-center justify-center group-hover:bg-muted/80",children:e.jsx(Re,{className:"w-6 h-6 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-bold text-foreground group-hover:text-foreground tracking-tight",children:"Authenticator App"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Use Google Authenticator, Authy, or 1Password. (Recommended)"})]})]})}),e.jsx("div",{role:"button",tabIndex:0,onClick:t,onKeyDown:a=>a.key==="Enter"&&t(),className:"p-6 border border-border rounded-xl bg-card opacity-50 cursor-not-allowed transition-all duration-[var(--duration-normal)] grayscale group",children:e.jsxs("div",{className:"flex items-center gap-4 mb-2",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-warning/10 flex items-center justify-center",children:e.jsx(he,{className:"w-6 h-6 text-warning"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-bold text-foreground tracking-tight",children:"SMS / Text Message"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Receive a code via text message to your phone."})]})]})})]})}function es({method:s,loading:t,setupData:a,verificationCode:r,onVerificationCodeChange:i,onVerify:l,onCopySecret:c,onSendSmsPlaceholder:o}){const h=r.replace(/\D/g,"").slice(0,6);return s==="sms"?e.jsxs("div",{className:"bg-card p-8 rounded-xl border border-border text-center",children:[e.jsx(he,{className:"w-16 h-16 text-warning mx-auto mb-4"}),e.jsx("h3",{className:"text-xl font-bold text-foreground mb-2 tracking-tight",children:"SMS Setup"}),e.jsx("p",{className:"text-muted-foreground mb-6",children:"Enter your phone number to receive a verification code."}),e.jsxs("div",{className:"flex gap-2 max-w-sm mx-auto",children:[e.jsx(A,{placeholder:"+1 (555) 000-0000"}),e.jsx(b,{variant:"primary",onClick:o,children:"SEND"})]}),e.jsxs("div",{className:"mt-8 border-t border-border pt-6 text-left",children:[e.jsx("h4",{className:"font-bold text-foreground mb-4 tracking-tight",children:"Enter Verification Code"}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(A,{placeholder:"000000",value:r,onChange:u=>i(u.target.value.replace(/\D/g,"").slice(0,6)),className:"font-mono text-center tracking-widest text-lg"}),e.jsx(b,{variant:"primary",onClick:l,disabled:h.length!==6,children:"VERIFY"})]})]})]}):e.jsxs("div",{className:"space-y-8 bg-card p-8 rounded-xl border border-border",children:[e.jsx("div",{className:"text-center",children:t&&!a?e.jsx("div",{className:"w-48 h-48 mx-auto flex items-center justify-center",children:e.jsx(ae,{className:"w-10 h-10 text-primary animate-spin"})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"bg-white p-4 inline-block rounded-xl mb-4 shadow-glow-cyan/20",children:e.jsx("img",{src:a?.qr_code_url,alt:"QR Code",className:"w-48 h-48"})}),e.jsx("p",{className:"text-sm text-foreground mb-2",children:"Scan this QR code with your authenticator app."}),e.jsxs("p",{role:"button",tabIndex:0,className:"text-xs text-muted-foreground font-mono bg-muted py-1 px-3 rounded-full border border-border inline-block cursor-pointer hover:text-foreground transition-colors duration-[var(--duration-normal)]",onClick:c,onKeyDown:u=>u.key==="Enter"&&c(),children:["KEY: ",a?.secret]})]})}),e.jsxs("div",{className:"border-t border-border pt-6",children:[e.jsxs("h4",{className:"font-bold text-foreground mb-4 flex items-center gap-2 tracking-tight",children:[e.jsx(xe,{className:"w-4 h-4 text-primary"})," Verify Configuration"]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(A,{placeholder:"Enter 6-digit code",value:r,onChange:u=>i(u.target.value.replace(/\D/g,"").slice(0,6)),className:"font-mono text-center tracking-[0.5em] text-lg border-primary/20 focus:border-primary"}),e.jsx(b,{variant:"primary",onClick:l,disabled:h.length!==6||t,className:"shadow-glow-cyan",children:t?e.jsx(ae,{className:"w-4 h-4 animate-spin"}):"VERIFY"})]})]})]})}function ss({setupData:s,onCopy:t,onDownload:a,onComplete:r}){return e.jsxs("div",{className:"space-y-6 bg-card p-8 rounded-xl border border-border shadow-2xl",children:[e.jsxs("div",{className:"flex items-center gap-4 text-lime-500 mb-2",children:[e.jsx(xe,{className:"w-8 h-8"}),e.jsx("h3",{className:"text-xl font-bold",children:"2FA Enabled Successfully"})]}),e.jsxs("div",{className:"bg-orange-500/10 border border-orange-500/30 p-4 rounded-lg flex gap-4",children:[e.jsx(Pe,{className:"w-6 h-6 text-orange-500 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-bold text-orange-500 text-sm mb-1",children:"Save these backup codes"}),e.jsx("p",{className:"text-xs text-foreground leading-relaxed",children:"If you lose your device, these codes are the only way to access your account. Store them in a password manager."})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-3 bg-muted/50 p-6 rounded-xl font-mono text-sm text-foreground text-center border border-border group",children:s?.recovery_codes.map(i=>e.jsx("div",{className:"py-2 tracking-widest border border-transparent hover:border-white/10 rounded transition-colors bg-white/2",children:i},i))}),e.jsxs("div",{className:"flex gap-4 pt-2",children:[e.jsx(b,{variant:"secondary",className:"flex-1",icon:e.jsx(Le,{className:"w-4 h-4"}),onClick:t,children:"Copy"}),e.jsx(b,{variant:"secondary",className:"flex-1",icon:e.jsx(se,{className:"w-4 h-4"}),onClick:a,children:"Download"}),e.jsx(b,{variant:"primary",className:"flex-1 shadow-glow-cyan",onClick:r,children:"Complete"})]})]})}function as(s,t){const{addToast:a}=ue(),[r,i]=n.useState(1),[l,c]=n.useState("totp"),[o,h]=n.useState(""),[u,x]=n.useState(!1),[m,p]=n.useState(null),[f,j]=n.useState(null),v=n.useCallback(async()=>{x(!0),j(null);try{const S=await te.setup();p(S)}catch{a("Failed to initialize 2FA setup","error"),j("Failed to initialize 2FA setup"),s()}finally{x(!1)}},[a,s]);n.useEffect(()=>{r===2&&l==="totp"&&!m&&!f&&v()},[r,l,m,f,v]);const k=n.useCallback(async()=>{if(o.length<6||!m){a("Invalid code","error");return}x(!0),j(null);try{await te.verify(m.secret,o),i(3),a("2FA Verified Successfully","success")}catch{a("Verification failed. Please check the code.","error"),j("Verification failed")}finally{x(!1)}},[o,m,a]),g=n.useCallback(()=>{m?.recovery_codes&&(navigator.clipboard.writeText(m.recovery_codes.join(`
|
|
`)),a("Backup codes copied to clipboard"))},[m,a]),N=n.useCallback(()=>{if(!m?.recovery_codes)return;const S=document.createElement("a"),V=new Blob([m.recovery_codes.join(`
|
|
`)],{type:"text/plain"});S.href=URL.createObjectURL(V),S.download="veza-backup-codes.txt",document.body.appendChild(S),S.click(),a("Backup codes downloaded")},[m,a]),C=n.useCallback(()=>{c("totp"),i(2)},[]),E=n.useCallback(()=>{a("SMS method not yet available in this region","info")},[a]);return{step:r,setStep:i,method:l,verificationCode:o,setVerificationCode:h,loading:u,setupData:m,error:f,fetchSetupData:v,handleVerify:k,copyCodes:g,downloadCodes:N,goToStep2Totp:C,handleSmsUnavailable:E}}function ts({onBack:s,onComplete:t}){const{addToast:a}=ue(),{step:r,method:i,verificationCode:l,setVerificationCode:c,loading:o,setupData:h,handleVerify:u,copyCodes:x,downloadCodes:m,goToStep2Totp:p,handleSmsUnavailable:f}=as(s),j=()=>{h&&(navigator.clipboard.writeText(h.secret),a("Secret Key copied"))};return e.jsxs("div",{className:"animate-fadeIn max-w-2xl mx-auto",children:[e.jsx(Ze,{onBack:s}),r===1&&e.jsx(Je,{onChooseTotp:p,onChooseSms:f}),r===2&&e.jsx(es,{method:i,loading:o,setupData:h,verificationCode:l,onVerificationCodeChange:c,onVerify:u,onCopySecret:j,onSendSmsPlaceholder:()=>a("Code sent to your phone","info")}),r===3&&e.jsx(ss,{setupData:h,onCopy:x,onDownload:m,onComplete:t})]})}const rs=()=>{const[s,t]=n.useState(null),[a,r]=n.useState(!0),[i,l]=n.useState(!1),c=async()=>{r(!0);try{const o=await te.getStatus();t(o.enabled)}catch(o){console.error("Failed to fetch 2FA status",o)}finally{r(!1)}};return n.useEffect(()=>{c()},[]),i?e.jsx(q,{className:"border-primary/20 bg-primary/5",children:e.jsx(H,{className:"pt-6",children:e.jsx(ts,{onBack:()=>l(!1),onComplete:()=>{l(!1),c()}})})}):e.jsxs(q,{children:[e.jsxs(K,{children:[e.jsxs(W,{className:"flex items-center gap-2",children:[e.jsx(pe,{className:"h-5 w-5"}),"Two-Factor Authentication (2FA)"]}),e.jsx($,{children:"Add an extra layer of security to your account"})]}),e.jsx(H,{children:a?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-lime-500/10 border border-lime-500/20 rounded-lg",children:[e.jsx(qe,{className:"h-8 w-8 text-lime-500"}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-bold text-white",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(b,{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.")&&t(!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(Ve,{className:"h-8 w-8 text-orange-500"}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-bold text-white",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(b,{onClick:()=>l(!0),children:"Setup 2FA"})]})})]})};function ns(){const{mutationError:s,retryCount:t,maxRetry:a,handleRetry:r,dismissError:i,isChangingPassword:l,currentPassword:c,setCurrentPassword:o,newPassword:h,setNewPassword:u,confirmPassword:x,setConfirmPassword:m,passwordError:p,handleChangePassword:f,isDeleteDialogOpen:j,setIsDeleteDialogOpen:v,isDeletingAccount:k,deletePassword:g,setDeletePassword:N,deleteReason:C,setDeleteReason:E,deleteConfirmText:S,setDeleteConfirmText:V,deleteValidationError:I,setDeleteValidationError:X,handleDeleteAccount:_,handleExportData:z}=Qe();return e.jsxs("div",{className:"space-y-6",children:[s&&e.jsx(Be,{error:s,retryCount:t,maxRetry:a,onRetry:r,onDismiss:i}),e.jsx(Ke,{currentPassword:c,setCurrentPassword:o,newPassword:h,setNewPassword:u,confirmPassword:x,setConfirmPassword:m,passwordError:p,isChangingPassword:l,onSubmit:f}),e.jsx(rs,{}),e.jsx(We,{onExport:z}),e.jsx($e,{isDeleteDialogOpen:j,setIsDeleteDialogOpen:v,isDeletingAccount:k,deletePassword:g,setDeletePassword:N,deleteReason:C,setDeleteReason:E,deleteConfirmText:S,setDeleteConfirmText:V,deleteValidationError:I,setDeleteValidationError:X,onDeleteAccount:_})]})}const os=[{value:"low",label:"Low (64 kbps)"},{value:"medium",label:"Medium (128 kbps)"},{value:"high",label:"High (256 kbps)"},{value:"lossless",label:"Lossless (FLAC)"}];function ls({playback:s,onChange:t}){const a=c=>{const o=Array.isArray(c)?c[0]:c;t({...s,quality:o})},r=c=>{t({...s,volume:c[0]})},i=c=>{t({...s,crossfade:c[0]})},l=c=>{t({...s,autoplay:c})};return e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"quality",children:"Audio Quality"}),e.jsx(ee,{options:os,value:s.quality,onChange:a,placeholder:"Select audio quality",name:"quality"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Higher quality uses more bandwidth"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(d,{htmlFor:"volume",children:["Default Volume: ",Math.round(s.volume*100),"%"]}),e.jsx(re,{id:"volume",min:0,max:1,step:.01,value:[s.volume],onValueChange:r,className:"w-full"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Default volume when starting playback"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(d,{htmlFor:"crossfade",children:["Crossfade: ",s.crossfade,"s"]}),e.jsx(re,{id:"crossfade",min:0,max:12,step:1,value:[s.crossfade],onValueChange:i,className:"w-full"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Fade duration between tracks (0-12 seconds)"})]}),e.jsxs("div",{className:"flex items-center justify-between pt-4 border-t",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(d,{htmlFor:"autoplay",children:"Autoplay"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically play next track in queue"})]}),e.jsx(w,{id:"autoplay",checked:s.autoplay,onCheckedChange:c=>l(c===!0)})]})]})})}function is({settings:s,onChange:t}){const a=o=>{t({...s,preferences:o})},r=o=>{t({...s,notifications:o})},i=o=>{t({...s,privacy:o})},l=o=>{t({...s,playback:o})},c=s.playback||{quality:"high",volume:.8,crossfade:3,autoplay:!0};return e.jsxs(Ae,{defaultValue:"account",className:"w-full",children:[e.jsxs(Ee,{className:"grid w-full grid-cols-5",children:[e.jsx(M,{value:"account",children:"Account"}),e.jsx(M,{value:"preferences",children:"Préférences"}),e.jsx(M,{value:"notifications",children:"Notifications"}),e.jsx(M,{value:"privacy",children:"Confidentialité"}),e.jsx(M,{value:"playback",children:"Playback"})]}),e.jsx(U,{value:"account",className:"mt-6",children:e.jsx(ns,{})}),e.jsx(U,{value:"preferences",className:"mt-6",children:e.jsx(Ge,{preferences:s.preferences,onChange:a})}),e.jsx(U,{value:"notifications",className:"mt-6",children:e.jsx(He,{notifications:s.notifications,onChange:r})}),e.jsx(U,{value:"privacy",className:"mt-6",children:e.jsx(Ye,{privacy:s.privacy,onChange:i})}),e.jsx(U,{value:"playback",className:"mt-6",children:e.jsx(ls,{playback:c,onChange:l})})]})}const cs=["en","fr","es","de","it","pt","ru","ja","zh","ko"],ds=["light","dark","auto"],us=O({notifications:O({email_notifications:y(),push_notifications:y(),browser_notifications:y(),email_on_follow:y(),email_on_like:y(),email_on_comment:y(),email_on_message:y(),email_on_mention:y(),email_marketing:y()}),privacy:O({allow_search_indexing:y(),show_activity:y()}),content:O({explicit_content:y(),autoplay:y()}),preferences:O({language:ie(cs,{errorMap:()=>({message:"Langue non supportée. Utilisez un code ISO 639-1 valide."})}),timezone:Me().refine(s=>{try{return Intl.DateTimeFormat(void 0,{timeZone:s}),!0}catch{return!1}},{message:"Fuseau horaire IANA invalide"}),theme:ie(ds,{errorMap:()=>({message:"Thème invalide. Valeurs autorisées: light, dark, auto"})})})});function _s(){const{data:s}=_e(),[t,a]=n.useState(null),[r,i]=n.useState(!0),[l,c]=n.useState(!1),[o,h]=n.useState(null),[u,x]=n.useState(null),[m,p]=n.useState(0),f=n.useRef(null),j=async()=>{if(!s?.id){h(new Error("Authentication required for system access.")),i(!1);return}try{i(!0),h(null);const g=await oe.getSettings(s.id);a(g)}catch(g){h(new Error(g instanceof Error?g.message:"Failed to load system configuration."))}finally{i(!1)}};n.useEffect(()=>{j()},[s?.id]);const v=async()=>{if(!s?.id||!t)return;const g=us.safeParse(t);if(!g.success){ne.error(`Configuration Error: ${g.error.errors.map(C=>C.message).join(", ")}`);return}const N=async()=>{await oe.updateSettings(s.id,t),ne.success("System configuration updated."),x(null),p(0),f.current=null};f.current=N,c(!0);try{await N()}catch(C){x(new Error(C instanceof Error?C.message:"Save failed."))}finally{c(!1)}},k=async()=>{if(!(!f.current||m>=3)){p(g=>g+1),c(!0);try{await f.current()}catch{}finally{c(!1)}}};return r?e.jsx("div",{className:"flex items-center justify-center min-h-screen",children:e.jsx(J,{})}):o&&!t?e.jsx("div",{className:"container mx-auto px-4 py-8 flex items-center justify-center min-h-layout-page",children:e.jsx(B,{error:o,variant:"card",severity:"error",onRetry:j})}):t?e.jsxs("div",{className:"container mx-auto px-4 py-8 pb-24 max-w-5xl",children:[u&&e.jsx(B,{error:u,variant:"banner",severity:"error",onRetry:m<3?k:void 0,onDismiss:()=>{x(null),p(0),f.current=null}}),e.jsxs("div",{className:"mb-8 flex items-end justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-4xl font-display font-bold text-white mb-2",children:"System Config"}),e.jsxs("p",{className:"text-muted-foreground flex items-center gap-2",children:[e.jsx(pe,{className:"w-4 h-4 text-primary"}),"Manage your neural link and interface preferences."]})]}),e.jsx(b,{onClick:v,disabled:l,className:"shadow-glow-cyan min-w-36",size:"lg",children:l?e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"mr-2 h-4 w-4"})," Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ie,{className:"mr-2 h-4 w-4"})," Save Config"]})})]}),e.jsxs(q,{variant:"glass",className:"overflow-hidden border-white/5 bg-black/40 backdrop-blur-xl",children:[e.jsxs("div",{className:"p-6 border-b border-white/5 bg-black/20 flex items-center gap-2",children:[e.jsx(ze,{className:"w-5 h-5 text-primary"}),e.jsx("h2",{className:"font-bold text-lg",children:"Global Preferences"})]}),e.jsx("div",{className:"p-6",children:e.jsx(is,{settings:t,onChange:a})})]})]}):e.jsx("div",{className:"flex items-center justify-center min-h-screen",children:e.jsx(J,{})})}export{_s as SettingsPage};
|