import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{m as t,n,r}from"./cn-BOQea7EA.js";import{ln as i,sn as a}from"./vendor-core-CvqwRnws.js";import{An as o,Fn as s,Ji as c,Qn as l,Wi as u,Zi as d,ia as f,mr as p,ra as m}from"./vendor-react-Vbe32VU9.js";import{r as h,t as g}from"./button-BxVMmVxn.js";import{a as _,c as v,i as y,l as b,n as x,o as S,r as C,t as w}from"./input-Kn9SJu2o.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 d({mutationFn:e=>T(e)})}var D=a({id:i(),firstname:i({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:i({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:i({error:`Please enter your new password.`}).min(8,{error:`Password must be 8 characters or more.`}).or(i().max(0)),confirmNewPassword:i().optional()}).refine(e=>e.newPassword===e.confirmNewPassword,{error:`Passwords do not match`,path:[`confirmNewPassword`]}),O=e(f(),1),k=m();function A(){let e=c(),t=u(),{user:i}=h(),a=s({resolver:o(D),defaultValues:{confirmNewPassword:``,firstname:i?.firstname||``,id:i?.id||``,lastname:i?.lastname||``,newPassword:``}}),{control:d,handleSubmit:f,reset:m,formState:{defaultValues:T,isDirty:A,isValid:j}}=a,{mutate:M,isPending:N}=E(),P=(0,O.useCallback)(async i=>{i&&M(i,{onSuccess:a=>{m({...T,...a}),r.updateUserForEntity(n,a),i.newPassword?(l.success(`Profile updated successfully!`,{description:`Please sign in with your new password.`}),b(),t({to:`/sign-in`}),e.invalidate()):l.success(`Profile updated successfully!`)}})},[T,t,m,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)(v,{...a,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)(_,{control:d,name:`firstname`,render:({field:e})=>(0,k.jsxs)(y,{children:[(0,k.jsx)(C,{className:`pb-1`,children:`First Name`}),(0,k.jsx)(S,{children:(0,k.jsx)(w,{type:`text`,className:`bg-purple-400 border-purple-400 dark:bg-black dark:border-black`,autoCapitalize:`words`,autoFocus:!0,...e})}),(0,k.jsx)(x,{})]})}),(0,k.jsx)(_,{control:d,name:`lastname`,render:({field:e})=>(0,k.jsxs)(y,{children:[(0,k.jsx)(C,{className:`pb-1`,children:`Last Name`}),(0,k.jsx)(S,{children:(0,k.jsx)(w,{type:`text`,className:`bg-purple-400 border-purple-400 dark:bg-black dark:border-black`,autoCapitalize:`words`,...e})}),(0,k.jsx)(x,{})]})}),(0,k.jsx)(C,{className:`pb-1`,children:`Email`}),(0,k.jsx)(S,{children:(0,k.jsx)(w,{type:`email`,enterKeyHint:`next`,autoComplete:`email`,autoCapitalize:`none`,value:i?.email||``,disabled:!0,readOnly:!0})}),(0,k.jsx)(_,{control:d,name:`newPassword`,render:({field:e})=>(0,k.jsxs)(y,{children:[(0,k.jsx)(C,{className:`pb-1`,children:`New Password`}),(0,k.jsx)(S,{children:(0,k.jsx)(w,{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)(x,{})]})}),(0,k.jsx)(_,{control:d,name:`confirmNewPassword`,render:({field:e})=>(0,k.jsxs)(y,{children:[(0,k.jsx)(C,{className:`pb-1`,children:`Confirm New Password`}),(0,k.jsx)(S,{children:(0,k.jsx)(w,{type:`password`,className:`bg-purple-400 border-purple-400 dark:bg-black dark:border-black`,autoComplete:`new-password`,autoCapitalize:`none`,...e})}),(0,k.jsx)(x,{})]})}),(0,k.jsx)(`div`,{className:`flex justify-between w-full`,children:(0,k.jsxs)(g,{type:`submit`,variant:`submit`,className:`rounded-full`,disabled:N||!A||!j,children:[(0,k.jsx)(p,{}),` Update Profile`]})})]})})]})}export{A as ProfileIndex};
//# sourceMappingURL=profile-BuZ1ni1t.js.map