1import{d as V,u as _,r as a,b as z,j as e,L as w}from"./vendor-query-BqeRHL1O.js";import{u as G,b as v}from"./index-Dzllbn4p.js";import"./vendor-react-qkC6yhPU.js";import"./vendor-radix-DqMENufp.js";function ee(){const[,d]=V(),{user:l,isLoading:h,isAuthenticated:y}=G(),u=_(),[E,R]=a.useState(""),[n,B]=a.useState(""),[p,H]=a.useState(""),[C,j]=a.useState(!1),[N,s]=a.useState(""),[x,k]=a.useState(""),[b,F]=a.useState(""),[P,S]=a.useState(!1),[A,i]=a.useState(""),[J,m]=a.useState(!1),[f,D]=a.useState(""),[q,L]=a.useState(!1),[O,c]=a.useState(""),[U,Q]=a.useState(!1),{data:g}=z({queryKey:["/api/dashboard/me"],queryFn:async()=>{const t=await fetch("/api/dashboard/me",{credentials:"include"});return t.ok?t.json():{mviAmount:null,totalRevenuePence:0,level:0,levelProgress:{}}},enabled:y});a.useEffect(()=>{!h&&!y&&d("/login")},[h,y,d]);const T=async()=>{if(s(""),!E||!n||!p){s("All fields are required.");return}if(n.length<8){s("New password must be at least 8 characters.");return}if(n!==p){s("New passwords do not match.");return}j(!0);try{await v("PATCH","/api/auth/password",{currentPassword:E,newPassword:n,confirmPassword:p}),u.setQueryData(["/api/auth/me"],null),u.invalidateQueries({queryKey:["/api/auth/me"]}),d("/login?reason=password_changed")}catch(t){let r="Failed to change password. Please try again.";if(t instanceof Error){const o=t.message.match(/^\d+: (.+)$/);if(o)try{r=JSON.parse(o[1]).error??r}catch{r=o[1]}else r=t.message}s(r)}j(!1)};function K(t,r){if(t instanceof Error){const o=t.message.match(/^\d+: (.+)$/);if(o)try{return JSON.parse(o[1]).error??r}catch{return o[1]}}return r}const $=async()=>{if(i(""),m(!1),!x.trim()||!b){i("Both fields are required.");return}S(!0);try{await v("PATCH","/api/auth/email",{newEmail:x.trim(),password:b}),u.invalidateQueries({queryKey:["/api/auth/me"]}),k(""),F(""),m(!0),window.setTimeout(()=>m(!1),4e3)}catch(t){i(K(t,"Failed to update email. Please try again."))}S(!1)},M=async()=>{if(c(""),!f){c("Password is required to delete your account.");return}L(!0);try{await v("DELETE","/api/auth/account",{password:f}),u.setQueryData(["/api/auth/me"],null),d("/")}catch(t){c(K(t,"Failed to delete account. Please try again."))}L(!1)};return h||!l?e.jsx("div",{className:"min-h-screen flex items-center justify-center",style:{backgroundColor:"#EEEEEE"},children:e.jsx("p",{className:"text-sm uppercase tracking-widest",style:{color:"#31363F77"},children:"Loadingâ¦"})}):(g?.level??l.level,g?.mviAmount??l.mviAmount,g?.totalRevenuePence,e.jsx("div",{className:"min-h-screen",style:{backgroundColor:"#EEEEEE"},children:e.jsxs("div",{className:"max-w-2xl mx-auto px-4 py-12",children:[e.jsxs("div",{className:"flex items-start justify-between mb-10",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl md:text-4xl font-black uppercase tracking-tight mb-1",style:{fontFamily:"'Paytone One', sans-serif",color:"#31363F",letterSpacing:"-0.05em"},"data-testid":"heading-profile",children:"Account Settings"}),e.jsx("p",{className:"text-sm",style:{color:"#31363F77"},children:l.email})]}),e.jsx(w,{href:"/dashboard",children:e.jsx("span",{"data-testid":"link-back-to-dashboard",className:"text-xs font-bold uppercase tracking-widest cursor-pointer hover:opacity-70 transition-opacity",style:{color:"#31363F77"},children:"â Dashboard"})})]}),e.jsxs("div",{className:"p-6 border mb-6",style:{borderColor:"#31363F22",backgroundColor:"#EEEEEE"},children:[e.jsx("h2",{className:"text-base font-black uppercase tracking-tight mb-1",style:{fontFamily:"'Paytone One', sans-serif",color:"#31363F",letterSpacing:"-0.03em"},children:"Change Email"}),e.jsxs("p",{className:"text-xs mb-5",style:{color:"#31363F77"},children:["Current email: ",e.jsx("span",{className:"font-bold",style:{color:"#31363F"},children:l.email})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("input",{"data-testid":"input-new-email",type:"email",placeholder:"New email address",value:x,onChange:t=>{k(t.target.value),i(""),m(!1)},className:"w-full px-3 py-2 border text-sm outline-none",style:{borderColor:"#31363F44",color:"#31363F",backgroundColor:"#EEEEEE"}}),e.jsx("input",{"data-testid":"input-email-password",type:"password",placeholder:"Current password (to confirm)",value:b,onChange:t=>{F(t.target.value),i("")},className:"w-full px-3 py-2 border text-sm outline-none",style:{borderColor:"#31363F44",color:"#31363F",backgroundColor:"#EEEEEE"}}),e.jsx("button",{"data-testid":"button-change-email",onClick:$,disabled:P,className:"px-5 py-2 text-xs font-bold uppercase tracking-widest hover:opacity-80 transition-opacity disabled:opacity-40",style:{backgroundColor:"#31363F",color:"#EEEEEE"},children:P?"Savingâ¦":"Update Email"})]}),J&&e.jsx("p",{"data-testid":"status-email-saved",className:"text-xs font-bold mt-3",style:{color:"#31363F"},children:"â Email updated"}),A&&e.jsx("p",{"data-testid":"status-email-error",className:"text-xs font-bold mt-3",style:{color:"#31363F"},children:A})]}),e.jsxs("div",{className:"p-6 border mb-6",style:{borderColor:"#31363F22",backgroundColor:"#EEEEEE"},children:[e.jsx("h2",{className:"text-base font-black uppercase tracking-tight mb-1",style:{fontFamily:"'Paytone One', sans-serif",color:"#31363F",letterSpacing:"-0.03em"},children:"Change Password"}),e.jsx("p",{className:"text-xs mb-5",style:{color:"#31363F77"},children:"Enter your current password and choose a new one (min. 8 characters)."}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("input",{"data-testid":"input-current-password",type:"password",placeholder:"Current password",value:E,onChange:t=>{R(t.target.value),s("")},className:"w-full px-3 py-2 border text-sm outline-none",style:{borderColor:"#31363F44",color:"#31363F",backgroundColor:"#EEEEEE"}}),e.jsx("input",{"data-testid":"input-new-password",type:"password",placeholder:"New password",value:n,onChange:t=>{B(t.target.value),s("")},className:"w-full px-3 py-2 border text-sm outline-none",style:{borderColor:"#31363F44",color:"#31363F",backgroundColor:"#EEEEEE"}}),e.jsx("input",{"data-testid":"input-confirm-password",type:"password",placeholder:"Confirm new password",value:p,onChange:t=>{H(t.target.value),s("")},onKeyDown:t=>t.key==="Enter"&&T(),className:"w-full px-3 py-2 border text-sm outline-none",style:{borderColor:"#31363F44",color:"#31363F",backgroundColor:"#EEEEEE"}}),e.jsx("button",{"data-testid":"button-change-password",onClick:T,disabled:C,className:"px-5 py-2 text-xs font-bold uppercase tracking-widest hover:opacity-80 transition-opacity disabled:opacity-40",style:{backgroundColor:"#31363F",color:"#EEEEEE"},children:C?"Savingâ¦":"Update Password"})]}),N&&e.jsx("p",{"data-testid":"status-password-error",className:"text-xs font-bold mt-3",style:{color:"#31363F"},children:N})]}),e.jsxs("div",{className:"p-6 border mb-6",style:{borderColor:"#31363F22",backgroundColor:"#EEEEEE"},children:[e.jsx("h2",{className:"text-base font-black uppercase tracking-tight mb-4",style:{fontFamily:"'Paytone One', sans-serif",color:"#31363F",letterSpacing:"-0.03em"}
1,children:"Quick Links"}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(w,{href:"/leaderboard",children:e.jsx("span",{"data-testid":"link-leaderboard",className:"block text-sm font-bold underline cursor-pointer hover:opacity-70 transition-opacity",style:{color:"#31363F"},children:"View leaderboard â"})}),e.jsx(w,{href:"/dashboard",children:e.jsx("span",{"data-testid":"link-dashboard",className:"block text-sm font-bold underline cursor-pointer hover:opacity-70 transition-opacity",style:{color:"#31363F"},children:"Back to dashboard â"})})]})]}),e.jsxs("div",{className:"p-6 border",style:{borderColor:"rgba(49,54,63,0.2)",backgroundColor:"#EEEEEE"},children:[e.jsx("h2",{className:"text-base font-black uppercase tracking-tight mb-1",style:{fontFamily:"'Paytone One', sans-serif",color:"#31363F",letterSpacing:"-0.03em"},children:"Delete Account"}),e.jsx("p",{className:"text-xs mb-4",style:{color:"rgba(49,54,63,0.6)"},children:"This permanently deletes your account and all data. This cannot be undone."}),U?e.jsxs("div",{className:"space-y-3",children:[e.jsx("input",{"data-testid":"input-delete-password",type:"password",placeholder:"Enter your password to confirm",value:f,onChange:t=>{D(t.target.value),c("")},className:"w-full px-3 py-2 border text-sm outline-none",style:{borderColor:"rgba(49,54,63,0.2)",color:"#31363F",backgroundColor:"#EEEEEE"}}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{"data-testid":"button-delete-account-confirm",onClick:M,disabled:q,className:"px-5 py-2 text-xs font-bold uppercase tracking-widest hover:opacity-80 transition-opacity disabled:opacity-40",style:{backgroundColor:"#31363F",color:"#EEEEEE"},children:q?"Deletingâ¦":"Confirm Delete"}),e.jsx("button",{"data-testid":"button-delete-account-cancel",onClick:()=>{Q(!1),D(""),c("")},className:"px-5 py-2 text-xs font-bold uppercase tracking-widest hover:opacity-80 transition-opacity",style:{borderColor:"#31363F33",color:"#31363F77",border:"1px solid #31363F33"},children:"Cancel"})]}),O&&e.jsx("p",{"data-testid":"status-delete-error",className:"text-xs font-bold mt-1",style:{color:"#31363F"},children:O})]}):e.jsx("button",{"data-testid":"button-delete-account-prompt",onClick:()=>Q(!0),className:"px-5 py-2 text-xs font-bold uppercase tracking-widest hover:opacity-80 transition-opacity border",style:{borderColor:"#31363F",color:"#31363F",backgroundColor:"transparent"},children:"Delete My Account"})]})]})}))}export{ee as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.