import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{h as t,i as n,r,t as i}from"./button-B_oawaxm.js";import{Nt as a,jt as o}from"./vendor-core-8FI3Cbaa.js";import{Aa as s,Fr as c,Kn as l,La as u,Pa as d,Ua as f,Wa as p,Zn as m,mr as h}from"./vendor-react-9UzkyydK.js";import{A as g,D as _,E as v,I as y,K as b,M as x,O as S,j as C,k as w}from"./index-CgbKZc--.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 u({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(p(),1),k=f();function A(){let e=d(),t=s(),{user:a}=b(),o=m({resolver:l(D),defaultValues:{confirmNewPassword:``,firstname:a?.firstname||``,id:a?.id||``,lastname:a?.lastname||``,newPassword:``}}),{control:u,handleSubmit:f,reset:p,formState:{defaultValues:T,isDirty:A,isValid:j}}=o,{mutate:M,isPending:N}=E(),P=(0,O.useCallback)(async i=>{i&&M(i,{onSuccess:a=>{p({...T,...a}),n.updateUserForEntity(r,a),i.newPassword?(h.success(`Profile updated successfully!`,{description:`Please sign in with your new password.`}),y(),t({to:`/sign-in`}),e.invalidate()):h.success(`Profile updated successfully!`)}})},[T,t,p,e,M]);return(0,k.jsxs)(`div`,{className:`mt-20 px-4 pt-4 md:px-12 max-w-2xl`,children:[(0,k.jsx)(`h1`,{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:f(P),className:`grid gap-4 my-4`,children:[(0,k.jsx)(g,{control:u,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)(v,{type:`text`,className:`dark:bg-black dark:border-black`,autoCapitalize:`words`,autoFocus:!0,...e})}),(0,k.jsx)(_,{})]})}),(0,k.jsx)(g,{control:u,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)(v,{type:`text`,className:`dark:bg-black dark:border-black`,autoCapitalize:`words`,...e})}),(0,k.jsx)(_,{})]})}),(0,k.jsxs)(w,{children:[(0,k.jsx)(S,{htmlFor:`profile-email`,className:`pb-1`,children:`Email`}),(0,k.jsx)(C,{children:(0,k.jsx)(v,{id:`profile-email`,type:`email`,enterKeyHint:`next`,autoComplete:`email`,autoCapitalize:`none`,value:a?.email||``,disabled:!0,readOnly:!0})})]}),(0,k.jsx)(g,{control:u,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)(v,{type:`password`,placeholder:`Optional`,className:`dark:bg-black dark:border-black`,autoComplete:`new-password`,autoCapitalize:`none`,...e})}),(0,k.jsx)(_,{})]})}),(0,k.jsx)(g,{control:u,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)(v,{type:`password`,className:`dark:bg-black dark:border-black`,autoComplete:`new-password`,autoCapitalize:`none`,...e})}),(0,k.jsx)(_,{})]})}),(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)(c,{}),` Update Profile`]})})]})})]})}export{A as ProfileIndex};
//# sourceMappingURL=profile-CYGLFi1u.js.map