import{c as e,d as t,f as n,h as r,l as i,t as a,u as o}from"./src-C0xjWfnx.js";import{t as s}from"./useNavigate-VRicZWJI.js";import{n as c}from"./trpc-client-QrVjRqP1.js";import{l}from"./index-BXnbw4dQ.js";var u=r(n()),d=t();function f(){s();let{user:t,logout:n,loginWithToken:r}=l(),[f,p]=(0,u.useState)(t?.name||``),[m,h]=(0,u.useState)(t?.email||``),g=c.user.auth.updateProfile.useMutation({onSuccess:e=>{e.token&&e.user&&r(e.token,e.user)}}),_=c.user.auth.deleteAccount.useMutation({onSuccess:()=>n()});return(0,d.jsxs)(a,{children:[(0,d.jsx)(o,{weight:`bold`,className:`mb-4 text-xl`,children:`Edit Profile`}),(0,d.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),g.mutate({name:f,email:m})},className:`flex flex-col gap-4`,children:[(0,d.jsx)(e,{placeholder:`Name`,value:f,onChange:e=>p(e.target.value)}),(0,d.jsx)(e,{placeholder:`Email`,type:`email`,value:m,onChange:e=>h(e.target.value)}),(0,d.jsx)(e,{placeholder:`Mobile`,value:t?.mobile||``,disabled:!0,className:`bg-gray-50`}),(0,d.jsx)(i,{type:`submit`,fullWidth:!0,disabled:g.isPending,textContent:g.isPending?`Saving...`:`Save Changes`,className:`bg-brand-500 text-white`})]}),(0,d.jsxs)(`div`,{className:`mt-8 border-t border-gray-200 pt-8`,children:[(0,d.jsx)(i,{fullWidth:!0,variant:`red`,onClick:()=>n(),textContent:`Logout`}),(0,d.jsx)(i,{fullWidth:!0,variant:`red`,onClick:()=>{window.confirm(`Are you sure you want to delete your account?`)&&_.mutate({mobile:t?.mobile||``})},disabled:_.isPending,textContent:_.isPending?`Deleting...`:`Delete My Account`,className:`mt-3 bg-red-600 text-white`})]})]})}export{f as component};