import{a as e}from"./rolldown-runtime-BYbx6iT9.js";import{h as t,i as n,r,t as i}from"./button-V4IQ8FFq.js";import{Nt as a,jt as o}from"./vendor-core-f32UXcS5.js";import{Fa as s,Oa as c,Pa as l,Pr as u,Qn as d,Ta as f,hr as p,qn as m,xa as h}from"./vendor-react-Dj1rnUQ4.js";import{n as g}from"./useAuth-DqzxNJHV.js";import{A as _,D as v,E as y,I as b,M as x,O as S,j as C,k as w}from"./index-BIjBsaWw.js";async function T(e){let{id:n,newPassword:r,confirmNewPassword:i,...a}=e,o={...a};r&&r===i&&(o.password=r);let{data:s}=await t.patch(`/User/${n}`,o);return s}function E(){return c({mutationFn:e=>T(e)})}var D=o({id:a(),firstname:a({error:`Please enter your first name.`}).min(2,{error:`First name is required.`}).max(50,{error:`First name must be less than 50 characters.`}),lastname:a({error:`Please enter your last name.`}).min(2,{error:`Last name is required.`}).max(50,{error:`Last name must be less than 50 characters.`}),newPassword:a({error:`Please enter your new password.`}).min(8,{error:`Password must be 8 characters or more.`}).or(a().max(0)),confirmNewPassword:a().optional()}).refine(e=>e.newPassword===e.confirmNewPassword,{error:`Passwords do not match`,path:[`confirmNewPassword`]}),O=e(s(),1),k=l();function A(){let e=f(),t=h(),{user:a}=g(),o=d({resolver:m(D),defaultValues:{confirmNewPassword:``,firstname:a?.firstname||``,id:a?.id||``,lastname:a?.lastname||``,newPassword:``}}),{control:s,handleSubmit:c,reset:l,formState:{defaultValues:T,isDirty:A,isValid:j}}=o,{mutate:M,isPending:N}=E(),P=(0,O.useCallback)(async i=>{i&&M(i,{onSuccess:a=>{l({...T,...a}),n.updateUserForEntity(r,a),i.newPassword?(p.success(`Profile updated successfully!`,{description:`Please sign in with your new password.`}),b(),t({to:`/sign-in`}),e.invalidate()):p.success(`Profile updated successfully!`)}})},[T,t,l,e,M]);return(0,k.jsxs)(`div`,{className:`mt-20 px-4 pt-4 md:px-12 max-w-2xl`,children:[(0,k.jsx)(`h2`,{className:`text-2xl font-light`,children:`Profile`}),(0,k.jsx)(x,{...o,children:(0,k.jsxs)(`form`,{id:`profile-edit-form`,name:`profile-edit-form`,onSubmit:c(P),className:`grid gap-4 my-4`,children:[(0,k.jsx)(_,{control:s,name:`firstname`,render:({field:e})=>(0,k.jsxs)(w,{children:[(0,k.jsx)(S,{className:`pb-1`,children:`First Name`}),(0,k.jsx)(C,{children:(0,k.jsx)(y,{type:`text`,className:`bg-purple-400 border-purple-400 dark:bg-black dark:border-black`,autoCapitalize:`words`,autoFocus:!0,...e})}),(0,k.jsx)(v,{})]})}),(0,k.jsx)(_,{control:s,name:`lastname`,render:({field:e})=>(0,k.jsxs)(w,{children:[(0,k.jsx)(S,{className:`pb-1`,children:`Last Name`}),(0,k.jsx)(C,{children:(0,k.jsx)(y,{type:`text`,className:`bg-purple-400 border-purple-400 dark:bg-black dark:border-black`,autoCapitalize:`words`,...e})}),(0,k.jsx)(v,{})]})}),(0,k.jsx)(S,{className:`pb-1`,children:`Email`}),(0,k.jsx)(C,{children:(0,k.jsx)(y,{type:`email`,enterKeyHint:`next`,autoComplete:`email`,autoCapitalize:`none`,value:a?.email||``,disabled:!0,readOnly:!0})}),(0,k.jsx)(_,{control:s,name:`newPassword`,render:({field:e})=>(0,k.jsxs)(w,{children:[(0,k.jsx)(S,{className:`pb-1`,children:`New Password`}),(0,k.jsx)(C,{children:(0,k.jsx)(y,{type:`password`,placeholder:`Optional`,className:`bg-purple-400 border-purple-400 dark:bg-black dark:border-black`,autoComplete:`new-password`,autoCapitalize:`none`,...e})}),(0,k.jsx)(v,{})]})}),(0,k.jsx)(_,{control:s,name:`confirmNewPassword`,render:({field:e})=>(0,k.jsxs)(w,{children:[(0,k.jsx)(S,{className:`pb-1`,children:`Confirm New Password`}),(0,k.jsx)(C,{children:(0,k.jsx)(y,{type:`password`,className:`bg-purple-400 border-purple-400 dark:bg-black dark:border-black`,autoComplete:`new-password`,autoCapitalize:`none`,...e})}),(0,k.jsx)(v,{})]})}),(0,k.jsx)(`div`,{className:`flex justify-between w-full`,children:(0,k.jsxs)(i,{type:`submit`,variant:`submit`,className:`rounded-full`,disabled:N||!A||!j,children:[(0,k.jsx)(u,{}),` Update Profile`]})})]})})]})}export{A as ProfileIndex};
//# sourceMappingURL=profile-Dyrp-ZIJ.js.map