Bloc A - Code mort: - Suppression Studio (components, views, features) - Suppression gamification + services mock (projectService, storageService, gamificationService) - Mise à jour Sidebar, Navbar, locales Bloc B - Frontend: - Suppression modal.tsx deprecated, Modal.stories (doublon Dialog) - Feature flags: PLAYLIST_SEARCH, PLAYLIST_RECOMMENDATIONS, ROLE_MANAGEMENT = true - Suppression 19 tests orphelins, retrait exclusions vitest.config Bloc C - Backend: - Extraction routes_auth.go depuis router.go Bloc D - Rust: - Suppression security_legacy.rs (code mort, patterns déjà dans security/)
3 lines
36 KiB
JavaScript
3 lines
36 KiB
JavaScript
import{a as n,j as e}from"./vendor-react-yWUy5XPk.js";import{c as ue,h as Se,p as J,n as ke,g as V,i as W,C as z,b as K,d as $,e as X,f as Y,B as N,D as _e,u as me,l as Ae,o as re,v as Ee,L as Te,S as b,w as ne}from"./index-CYK_b1Uz.js";import{u as oe}from"./users-CZ92MzeH.js";import{T as Fe,a as De,b as O,c as G}from"./Tabs-jry2MOtG.js";import{L as h,I as E}from"./input-CGdBHtsQ.js";import{S as ee}from"./Select-DA2I33Xz.js";import{ah as Re,a2 as Pe,e as he,aa as se,i as le,A as Le,aS as qe,at as xe,g as ae,d as pe,b as Ve,a3 as Ie,W as fe,am as Ue,as as ze,u as Me,aT as Oe}from"./vendor-icons-DJFb1Tiw.js";import{C as w}from"./checkbox-DgTIon8S.js";import{A as ge,a as je}from"./alert-FT0GWKW4.js";import{r as Q}from"./features-DItyhINc.js";import{o as H,e as ie,s as Ge,b as v}from"./vendor-utils-DtoSyhX2.js";import"./vendor-CveO81sn.js";import"./vendor-security-DsrNJhpn.js";import"./vendor-router-BNNHboN9.js";import"./vendor-tanstack-kPY9uK0s.js";import"./vendor-http-Cz8wfb0q.js";import"./vendor-motion-B3XPS3Jc.js";import"./vendor-i18n-CMcqpBLz.js";import"./dropdown-CA3EXRNb.js";const ve=n.forwardRef(({className:s,value:a,onValueChange:t,disabled:r,children:l,...i},d)=>{const o=[];n.Children.forEach(l,c=>{n.isValidElement(c)&&c.type===U&&!c.props.disabled&&o.push(c.props.value)});const x=c=>{if(o.length===0)return;const m=a?o.indexOf(a):-1;let u;switch(c.key){case"ArrowDown":case"ArrowRight":u=m===-1?0:(m+1)%o.length;break;case"ArrowUp":case"ArrowLeft":u=m===-1?o.length-1:(m-1+o.length)%o.length;break;default:return}c.preventDefault();const f=o[u];f!==void 0&&t?.(f),c.currentTarget.querySelectorAll('input[type="radio"]')[u]?.focus()};return e.jsx("div",{ref:d,className:ue("grid gap-2",s),role:"radiogroup",onKeyDown:x,...i,children:n.Children.map(l,c=>{if(n.isValidElement(c)&&c.type===U){const m=c.props.value===a,u=c.props.value===o[0];return n.cloneElement(c,{checked:m,onCheckedChange:()=>t?.(c.props.value),disabled:r||c.props.disabled,tabIndex:m||a===void 0&&u?0:-1})}return c})})});ve.displayName="RadioGroup";const U=n.forwardRef(({className:s,value:a,checked:t,onCheckedChange:r,disabled:l,tabIndex:i,...d},o)=>e.jsxs("label",{role:"radio","aria-checked":!!t,className:ue("aspect-square h-4 w-4 rounded-full border border-border text-muted-foreground","ring-offset-background focus-within:outline-none focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2","disabled:cursor-not-allowed disabled:opacity-50","cursor-pointer relative inline-flex items-center justify-center",t&&"border-primary text-primary",s),children:[e.jsx("input",{ref:o,type:"radio",value:a,checked:t,onChange:r,disabled:l,tabIndex:i,className:"sr-only",...d}),t&&e.jsx(Re,{className:"h-2.5 w-2.5 fill-current text-current"})]}));U.displayName="RadioGroupItem";const He=[{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:"한국어"}],Ye=[{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 Be({preferences:s,onChange:a}){const t=i=>{a({...s,language:Array.isArray(i)?i[0]??"":i})},r=i=>{a({...s,timezone:Array.isArray(i)?i[0]??"":i})},l=i=>{a({...s,theme:i})};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(h,{htmlFor:"language",children:"Langue"}),e.jsx(ee,{options:He,value:s.language,onChange:t,placeholder:"Sélectionner une langue",name:"language"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"timezone",children:"Fuseau horaire"}),e.jsx(ee,{options:Ye,value:s.timezone,onChange:r,placeholder:"Sélectionner un fuseau horaire",name:"timezone"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{children:"Thème"}),e.jsxs(ve,{value:s.theme,onValueChange:l,children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(U,{value:"light",id:"theme-light"}),e.jsx(h,{htmlFor:"theme-light",className:"font-normal",children:"Clair"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(U,{value:"dark",id:"theme-dark"}),e.jsx(h,{htmlFor:"theme-dark",className:"font-normal",children:"Sombre"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(U,{value:"auto",id:"theme-auto"}),e.jsx(h,{htmlFor:"theme-auto",className:"font-normal",children:"Automatique"})]})]})]})]})})}function Qe({notifications:s,onChange:a}){const t=(r,l)=>{a({...s,[r]:l})};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(h,{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=>t("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(h,{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=>t("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(h,{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=>t("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(h,{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=>t("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(h,{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=>t("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(h,{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=>t("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(h,{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=>t("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(h,{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=>t("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(h,{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=>t("email_marketing",r===!0)})]})]})]})]})}function We({privacy:s,onChange:a}){const t=(r,l)=>{a({...s,[r]:l})};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(h,{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=>t("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(h,{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=>t("show_activity",r===!0)})]})]})})}const ce=3;function Ke(){const{logout:s}=Se(),a=ke(),[t,r]=n.useState(!1),[l,i]=n.useState(!1),[d,o]=n.useState(!1),[x,c]=n.useState(""),[m,u]=n.useState(""),[f,g]=n.useState(""),[y,j]=n.useState(""),[_,P]=n.useState(""),[C,L]=n.useState(""),[S,p]=n.useState(""),[T,k]=n.useState(null),[Z,A]=n.useState(null),[M,B]=n.useState(0),q=n.useRef(null),ye=n.useCallback(async F=>{if(F.preventDefault(),j(""),m!==f){j("New passwords do not match");return}if(m.length<12){j("Password must be at least 12 characters long");return}const D=async()=>{await V.put("/users/me/password",{current_password:x,new_password:m}),a.success("Password changed successfully"),c(""),u(""),g(""),A(null),B(0),q.current=null};q.current=D,r(!0);try{await D()}catch(I){const R=J(I);j(R.message),A(new Error(R.message))}finally{r(!1)}},[x,m,f,a]),be=n.useCallback(async()=>{if(k(null),A(null),S!=="DELETE"){k("Please type DELETE to confirm");return}try{i(!0),await V.delete("/users/me",{data:{password:_,reason:C,confirm_text:S}}),a.success("Account deletion requested. You will be logged out."),setTimeout(()=>{s(),window.location.href="/login"},2e3)}catch(F){const D=J(F);A(new Error(D.message))}finally{i(!1),o(!1)}},[_,C,S,a,s]),we=n.useCallback(async()=>{const F=async()=>{const D=await V.get("/users/me/export",{responseType:"blob"}),I=window.URL.createObjectURL(new Blob([D.data])),R=document.createElement("a");R.href=I,R.setAttribute("download",`veza-data-export-${new Date().toISOString()}.json`),document.body.appendChild(R),R.click(),R.remove(),window.URL.revokeObjectURL(I),a.success("Data export started"),A(null),B(0),q.current=null};q.current=F;try{await F()}catch(D){const I=J(D);A(new Error(I.message))}},[a]),Ne=n.useCallback(async()=>{if(!(!q.current||M>=ce)){B(F=>F+1);try{await q.current()}catch{}}},[M]),Ce=n.useCallback(()=>{A(null),B(0),q.current=null},[]);return{mutationError:Z,retryCount:M,maxRetry:ce,handleRetry:Ne,dismissError:Ce,isChangingPassword:t,currentPassword:x,setCurrentPassword:c,newPassword:m,setNewPassword:u,confirmPassword:f,setConfirmPassword:g,passwordError:y,handleChangePassword:ye,isDeleteDialogOpen:d,setIsDeleteDialogOpen:o,isDeletingAccount:l,deletePassword:_,setDeletePassword:P,deleteReason:C,setDeleteReason:L,deleteConfirmText:S,setDeleteConfirmText:p,deleteValidationError:T,setDeleteValidationError:k,handleDeleteAccount:be,handleExportData:we}}function $e({error:s,retryCount:a,maxRetry:t,onRetry:r,onDismiss:l}){return e.jsx(W,{error:s,variant:"banner",severity:"error",context:{action:"updating account settings",resource:"account"},onRetry:a<t?r:void 0,onDismiss:l})}function Xe({currentPassword:s,setCurrentPassword:a,newPassword:t,setNewPassword:r,confirmPassword:l,setConfirmPassword:i,passwordError:d,isChangingPassword:o,onSubmit:x}){return e.jsxs(z,{children:[e.jsxs(K,{children:[e.jsxs($,{className:"flex items-center gap-2",children:[e.jsx(Pe,{className:"h-5 w-5"}),"Change Password"]}),e.jsx(X,{children:"Update your password to keep your account secure"})]}),e.jsx(Y,{children:e.jsxs("form",{onSubmit:x,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"current-password",children:"Current Password"}),e.jsx(E,{id:"current-password",type:"password",value:s,onChange:c=>a(c.target.value),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"new-password",children:"New Password"}),e.jsx(E,{id:"new-password",type:"password",value:t,onChange:c=>r(c.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(h,{htmlFor:"confirm-password",children:"Confirm New Password"}),e.jsx(E,{id:"confirm-password",type:"password",value:l,onChange:c=>i(c.target.value),required:!0,minLength:12})]}),d&&e.jsxs(ge,{variant:"destructive",children:[e.jsx(he,{className:"h-4 w-4"}),e.jsx(je,{children:d})]}),e.jsx(N,{type:"submit",disabled:o,children:o?"Changing...":"Change Password"})]})})]})}function Ze({onExport:s}){return e.jsxs(z,{children:[e.jsxs(K,{children:[e.jsxs($,{className:"flex items-center gap-2",children:[e.jsx(se,{className:"h-5 w-5"}),"Data Export"]}),e.jsx(X,{children:"Download a copy of your data (GDPR)"})]}),e.jsx(Y,{children:e.jsxs(N,{variant:"outline",onClick:s,children:[e.jsx(se,{className:"mr-2 h-4 w-4"}),"Export My Data"]})})]})}function Je({isDeleteDialogOpen:s,setIsDeleteDialogOpen:a,isDeletingAccount:t,deletePassword:r,setDeletePassword:l,deleteReason:i,setDeleteReason:d,deleteConfirmText:o,setDeleteConfirmText:x,deleteValidationError:c,setDeleteValidationError:m,onDeleteAccount:u}){return e.jsxs(z,{className:"border-destructive",children:[e.jsxs(K,{children:[e.jsxs($,{className:"flex items-center gap-2 text-destructive",children:[e.jsx(le,{className:"h-5 w-5"}),"Delete Account"]}),e.jsx(X,{children:"Permanently delete your account and all associated data"})]}),e.jsxs(Y,{children:[e.jsxs(ge,{variant:"destructive",children:[e.jsx(he,{className:"h-4 w-4"}),e.jsx(je,{children:"This action cannot be undone. All your data will be permanently deleted."})]}),e.jsx(_e,{open:s,onClose:()=>a(!1),title:"Are you absolutely sure?",variant:"alert",onConfirm:u,confirmLabel:t?"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(h,{htmlFor:"delete-password",children:"Enter your password"}),e.jsx(E,{id:"delete-password",type:"password",value:r,onChange:f=>l(f.target.value),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"delete-reason",children:"Reason (optional)"}),e.jsx(E,{id:"delete-reason",value:i,onChange:f=>d(f.target.value),placeholder:"Why are you deleting your account?"})]}),c&&e.jsx(W,{error:c,variant:"inline",severity:"error",size:"sm",dismissible:!1}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(h,{htmlFor:"delete-confirm",children:["Type ",e.jsx("strong",{children:"DELETE"})," to confirm"]}),e.jsx(E,{id:"delete-confirm",value:o,onChange:f=>{x(f.target.value),m(null)},required:!0,placeholder:"DELETE"})]})]})}),e.jsxs(N,{variant:"destructive",className:"mt-4",onClick:()=>a(!0),children:[e.jsx(le,{className:"mr-2 h-4 w-4"}),"Delete Account"]})]})]})}class es{async getStatus(){return Q("TWO_FACTOR_AUTH"),(await V.get("/auth/2fa/status")).data}async setup(){return Q("TWO_FACTOR_AUTH"),(await V.post("/auth/2fa/setup")).data}async verify(a,t){Q("TWO_FACTOR_AUTH"),await V.post("/auth/2fa/verify",{secret:a,code:t})}async disable(a){Q("TWO_FACTOR_AUTH"),await V.post("/auth/2fa/disable",{password:a})}}const te=new es;function ss({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(--sumi-duration-normal)]","aria-label":"Go back",children:e.jsx(Le,{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 as({onChooseTotp:s,onChooseSms:a}){return e.jsxs("div",{className:"grid gap-4",children:[e.jsx("button",{type:"button",onClick:s,className:"appearance-none bg-transparent border-0 p-0 text-left w-full p-6 border border-border rounded-xl bg-card hover:bg-muted/50 cursor-pointer transition-all duration-[var(--sumi-duration-normal)] hover:border-primary/50 group focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",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(qe,{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("button",{type:"button",onClick:a,className:"appearance-none bg-transparent border-0 p-0 text-left w-full p-6 border border-border rounded-xl bg-card opacity-50 cursor-not-allowed transition-all duration-[var(--sumi-duration-normal)] grayscale group focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",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(xe,{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 ts({method:s,loading:a,setupData:t,verificationCode:r,onVerificationCodeChange:l,onVerify:i,onCopySecret:d,onSendSmsPlaceholder:o}){const x=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(xe,{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(E,{placeholder:"+1 (555) 000-0000"}),e.jsx(N,{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(E,{placeholder:"000000",value:r,onChange:c=>l(c.target.value.replace(/\D/g,"").slice(0,6)),className:"font-mono text-center tracking-widest text-lg"}),e.jsx(N,{variant:"primary",onClick:i,disabled:x.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:a&&!t?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-card p-4 inline-block rounded-xl mb-4 shadow-glow-cyan/20",children:e.jsx("img",{src:t?.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("button",{type:"button",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(--sumi-duration-normal)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background appearance-none",onClick:d,children:["KEY: ",t?.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(pe,{className:"w-4 h-4 text-primary"})," Verify Configuration"]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(E,{placeholder:"Enter 6-digit code",value:r,onChange:c=>l(c.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(N,{variant:"primary",onClick:i,disabled:x.length!==6||a,className:"shadow-glow-cyan",children:a?e.jsx(ae,{className:"w-4 h-4 animate-spin"}):"VERIFY"})]})]})]})}function rs({setupData:s,onCopy:a,onDownload:t,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-success mb-2",children:[e.jsx(pe,{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(Ve,{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(l=>e.jsx("div",{className:"py-2 tracking-widest border border-transparent hover:border-white/10 rounded transition-colors bg-white/2",children:l},l))}),e.jsxs("div",{className:"flex gap-4 pt-2",children:[e.jsx(N,{variant:"secondary",className:"flex-1",icon:e.jsx(Ie,{className:"w-4 h-4"}),onClick:a,children:"Copy"}),e.jsx(N,{variant:"secondary",className:"flex-1",icon:e.jsx(se,{className:"w-4 h-4"}),onClick:t,children:"Download"}),e.jsx(N,{variant:"primary",className:"flex-1 shadow-glow-cyan",onClick:r,children:"Complete"})]})]})}function ns(s,a){const{addToast:t}=me(),[r,l]=n.useState(1),[i,d]=n.useState("totp"),[o,x]=n.useState(""),[c,m]=n.useState(!1),[u,f]=n.useState(null),[g,y]=n.useState(null),j=n.useCallback(async()=>{m(!0),y(null);try{const p=await te.setup();f(p)}catch{t("Failed to initialize 2FA setup","error"),y("Failed to initialize 2FA setup"),s()}finally{m(!1)}},[t,s]);n.useEffect(()=>{r===2&&i==="totp"&&!u&&!g&&j()},[r,i,u,g,j]);const _=n.useCallback(async()=>{if(o.length<6||!u){t("Invalid code","error");return}m(!0),y(null);try{await te.verify(u.secret,o),l(3),t("2FA Verified Successfully","success")}catch{t("Verification failed. Please check the code.","error"),y("Verification failed")}finally{m(!1)}},[o,u,t]),P=n.useCallback(()=>{u?.recovery_codes&&(navigator.clipboard.writeText(u.recovery_codes.join(`
|
|
`)),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(Ze,{onExport:M}),e.jsx(Je,{isDeleteDialogOpen:y,setIsDeleteDialogOpen:j,isDeletingAccount:_,deletePassword:P,setDeletePassword:C,deleteReason:L,setDeleteReason:S,deleteConfirmText:p,setDeleteConfirmText:T,deleteValidationError:k,setDeleteValidationError:Z,onDeleteAccount:A})]})}const cs=[{value:"low",label:"Low (64 kbps)"},{value:"medium",label:"Medium (128 kbps)"},{value:"high",label:"High (256 kbps)"},{value:"lossless",label:"Lossless (FLAC)"}];function ds({playback:s,onChange:a}){const t=d=>{const o=Array.isArray(d)?d[0]:d;a({...s,quality:o})},r=d=>{a({...s,volume:d[0]??0})},l=d=>{a({...s,crossfade:d[0]??0})},i=d=>{a({...s,autoplay:d})};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(h,{htmlFor:"quality",children:"Audio Quality"}),e.jsx(ee,{options:cs,value:s.quality,onChange:t,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(h,{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(h,{htmlFor:"crossfade",children:["Crossfade: ",s.crossfade,"s"]}),e.jsx(re,{id:"crossfade",min:0,max:12,step:1,value:[s.crossfade],onValueChange:l,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(h,{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:d=>i(d===!0)})]})]})})}function us({settings:s,onChange:a}){const t=o=>{a({...s,preferences:o})},r=o=>{a({...s,notifications:o})},l=o=>{a({...s,privacy:o})},i=o=>{a({...s,playback:o})},d=s.playback||{quality:"high",volume:.8,crossfade:3,autoplay:!0};return e.jsxs(Fe,{defaultValue:"account",className:"w-full",children:[e.jsxs(De,{className:"grid w-full grid-cols-5",children:[e.jsx(O,{value:"account",children:"Account"}),e.jsx(O,{value:"preferences",children:"Préférences"}),e.jsx(O,{value:"notifications",children:"Notifications"}),e.jsx(O,{value:"privacy",children:"Confidentialité"}),e.jsx(O,{value:"playback",children:"Playback"})]}),e.jsx(G,{value:"account",className:"mt-6",children:e.jsx(is,{})}),e.jsx(G,{value:"preferences",className:"mt-6",children:e.jsx(Be,{preferences:s.preferences,onChange:t})}),e.jsx(G,{value:"notifications",className:"mt-6",children:e.jsx(Qe,{notifications:s.notifications,onChange:r})}),e.jsx(G,{value:"privacy",className:"mt-6",children:e.jsx(We,{privacy:s.privacy,onChange:l})}),e.jsx(G,{value:"playback",className:"mt-6",children:e.jsx(ds,{playback:d,onChange:i})})]})}const ms=["en","fr","es","de","it","pt","ru","ja","zh","ko"],hs=["light","dark","auto"],xs=H({notifications:H({email_notifications:v(),push_notifications:v(),browser_notifications:v(),email_on_follow:v(),email_on_like:v(),email_on_comment:v(),email_on_message:v(),email_on_mention:v(),email_marketing:v()}),privacy:H({allow_search_indexing:v(),show_activity:v()}),content:H({explicit_content:v(),autoplay:v()}),preferences:H({language:ie(ms,{errorMap:()=>({message:"Langue non supportée. Utilisez un code ISO 639-1 valide."})}),timezone:Ge().refine(s=>{try{return Intl.DateTimeFormat(void 0,{timeZone:s}),!0}catch{return!1}},{message:"Fuseau horaire IANA invalide"}),theme:ie(hs,{errorMap:()=>({message:"Thème invalide. Valeurs autorisées: light, dark, auto"})})})});function ps(s){n.useEffect(()=>{if(!s)return;const a=t=>{t.preventDefault(),t.returnValue=""};return window.addEventListener("beforeunload",a),()=>window.removeEventListener("beforeunload",a)},[s])}function fs(){const[s,a]=n.useState(!1),t=n.useCallback(()=>a(!0),[]),r=n.useCallback(()=>a(!1),[]);return{isDirty:s,markDirty:t,markClean:r}}function de(){return e.jsxs("div",{className:"container mx-auto px-4 py-8 pb-24 max-w-5xl",children:[e.jsxs("div",{className:"mb-8 flex items-end justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{className:"h-9 w-56"}),e.jsx(b,{className:"h-4 w-72"})]}),e.jsx(b,{className:"h-11 w-36 rounded-lg"})]}),e.jsxs("div",{className:"overflow-hidden rounded-xl border border-border bg-card/80 backdrop-blur-xl",children:[e.jsxs("div",{className:"p-6 border-b border-border bg-muted/20 flex items-center gap-2",children:[e.jsx(b,{variant:"circular",className:"h-5 w-5"}),e.jsx(b,{className:"h-5 w-40"})]}),e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsx("div",{className:"flex gap-2",children:Array.from({length:4}).map((s,a)=>e.jsx(b,{className:"h-9 w-24 rounded-lg"},a))}),e.jsxs("div",{className:"flex items-center gap-4 py-4",children:[e.jsx(b,{variant:"circular",className:"h-16 w-16"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{className:"h-5 w-36"}),e.jsx(b,{className:"h-4 w-48"})]})]}),Array.from({length:3}).map((s,a)=>e.jsxs("div",{className:"space-y-3 rounded-xl border border-border bg-muted/20 p-6",children:[e.jsx(b,{className:"h-5 w-40"}),e.jsx(b,{className:"h-4 w-full"}),e.jsx(b,{className:"h-4 w-3/4"})]},a))]})]})]})}function qs(){const{data:s}=Ee(),[a,t]=n.useState(null),[r,l]=n.useState(!0),[i,d]=n.useState(!1),[o,x]=n.useState(null),[c,m]=n.useState(null),[u,f]=n.useState(0),g=n.useRef(null),{isDirty:y,markDirty:j,markClean:_}=fs();ps(y);const P=n.useCallback(p=>{t(p),j()},[j]),C=async()=>{if(!s?.id){x(new Error("Authentication required for system access.")),l(!1);return}try{l(!0),x(null);const p=await oe.getSettings(s.id);t(p)}catch(p){x(new Error(p instanceof Error?p.message:"Failed to load system configuration."))}finally{l(!1)}};n.useEffect(()=>{C()},[s?.id]);const L=async()=>{if(!s?.id||!a)return;const p=xs.safeParse(a);if(!p.success){ne.error(`Configuration Error: ${p.error.errors.map(k=>k.message).join(", ")}`);return}const T=async()=>{await oe.updateSettings(s.id,a),ne.success("System configuration updated."),m(null),f(0),g.current=null,_()};g.current=T,d(!0);try{await T()}catch(k){m(new Error(k instanceof Error?k.message:"Save failed."))}finally{d(!1)}},S=async()=>{if(!(!g.current||u>=3)){f(p=>p+1),d(!0);try{await g.current()}catch{}finally{d(!1)}}};return r?e.jsx(de,{}):o&&!a?e.jsx("div",{className:"container mx-auto px-4 py-8 flex items-center justify-center min-h-layout-page",children:e.jsx(W,{error:o,variant:"card",severity:"error",onRetry:C})}):a?e.jsxs("div",{className:"container mx-auto px-4 py-8 pb-24 max-w-5xl",children:[c&&e.jsx(W,{error:c,variant:"banner",severity:"error",onRetry:u<3?S:void 0,onDismiss:()=>{m(null),f(0),g.current=null}}),e.jsxs("div",{className:"mb-8 flex items-end justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-display font-heading text-foreground mb-2",children:"System Config"}),e.jsxs("p",{className:"text-muted-foreground flex items-center gap-2",children:[e.jsx(fe,{className:"w-4 h-4 text-primary"}),"Manage your neural link and interface preferences."]})]}),e.jsx(N,{onClick:L,disabled:i,className:"shadow-glow-cyan min-w-36",size:"lg",children:i?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:"sm",inline:!0,className:"mr-2"})," Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Me,{className:"mr-2 h-4 w-4"})," Save Config"]})})]}),e.jsxs(z,{variant:"glass",className:"overflow-hidden border-border bg-card/80 backdrop-blur-xl",children:[e.jsxs("div",{className:"p-6 border-b border-border bg-muted/20 flex items-center gap-2",children:[e.jsx(Oe,{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(us,{settings:a,onChange:P})})]})]}):e.jsx(de,{})}export{qs as SettingsPage};
|