import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{h as t,i as n,r,t as i}from"./button-kCMf1ZBL.js";import{v as a,x as o}from"./vendor-core-BIhSIGPv.js";import{E as s,k as c,x as l}from"./vendor-tanstack-DmFvmRiZ.js";import{a as u}from"./vendor-datadog-Bq_0f1ke.js";import{r as d}from"./vendor-react-BqTNj-ZI.js";import{Tt as f,at as p,ut as m}from"./vendor-ui-to0aD0Fq.js";import{Ct as h,Mt as g,St as _,Tt as v,Xt as y,bt as b,vt as x,wt as S,yn as C,yt as w}from"./index-oRZw5GW3.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=a({id:o(),firstname:o({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:o({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:o({error:`Please enter your new password.`}).min(8,{error:`Password must be 8 characters or more.`}).or(o().max(0)),confirmNewPassword:o().optional()}).refine(e=>e.newPassword===e.confirmNewPassword,{error:`Passwords do not match`,path:[`confirmNewPassword`]}),O=e(u(),1),k=d();function A(){let e=s(),t=l(),{user:a}=C(),o=m({resolver:p(D),defaultValues:{confirmNewPassword:``,firstname:a?.firstname||``,id:a?.id||``,lastname:a?.lastname||``,newPassword:``}}),{control:c,handleSubmit:u,reset:d,formState:{defaultValues:T,isDirty:A,isValid:j}}=o,{mutate:M,isPending:N}=E(),P=(0,O.useCallback)(async i=>{i&&M(i,{onSuccess:a=>{d({...T,...a}),n.updateUserForEntity(r,a),i.newPassword?(f.success(`Profile updated successfully!`,{description:`Please sign in with your new password.`}),g(),t({to:`/sign-in`}),e.invalidate()):f.success(`Profile updated successfully!`)}})},[T,t,d,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)(v,{...o,children:(0,k.jsxs)(`form`,{id:`profile-edit-form`,name:`profile-edit-form`,onSubmit:u(P),className:`grid gap-4 my-4`,children:[(0,k.jsx)(h,{control:c,name:`firstname`,render:({field:e})=>(0,k.jsxs)(_,{children:[(0,k.jsx)(b,{className:`pb-1`,children:`First Name`}),(0,k.jsx)(S,{children:(0,k.jsx)(x,{type:`text`,className:`dark:bg-black dark:border-black`,autoCapitalize:`words`,autoFocus:!0,...e})}),(0,k.jsx)(w,{})]})}),(0,k.jsx)(h,{control:c,name:`lastname`,render:({field:e})=>(0,k.jsxs)(_,{children:[(0,k.jsx)(b,{className:`pb-1`,children:`Last Name`}),(0,k.jsx)(S,{children:(0,k.jsx)(x,{type:`text`,className:`dark:bg-black dark:border-black`,autoCapitalize:`words`,...e})}),(0,k.jsx)(w,{})]})}),(0,k.jsxs)(_,{children:[(0,k.jsx)(b,{htmlFor:`profile-email`,className:`pb-1`,children:`Email`}),(0,k.jsx)(S,{children:(0,k.jsx)(x,{id:`profile-email`,type:`email`,enterKeyHint:`next`,autoComplete:`email`,autoCapitalize:`none`,value:a?.email||``,disabled:!0,readOnly:!0})})]}),(0,k.jsx)(h,{control:c,name:`newPassword`,render:({field:e})=>(0,k.jsxs)(_,{children:[(0,k.jsx)(b,{className:`pb-1`,children:`New Password`}),(0,k.jsx)(S,{children:(0,k.jsx)(x,{type:`password`,placeholder:`Optional`,className:`dark:bg-black dark:border-black`,autoComplete:`new-password`,autoCapitalize:`none`,...e})}),(0,k.jsx)(w,{})]})}),(0,k.jsx)(h,{control:c,name:`confirmNewPassword`,render:({field:e})=>(0,k.jsxs)(_,{children:[(0,k.jsx)(b,{className:`pb-1`,children:`Confirm New Password`}),(0,k.jsx)(S,{children:(0,k.jsx)(x,{type:`password`,className:`dark:bg-black dark:border-black`,autoComplete:`new-password`,autoCapitalize:`none`,...e})}),(0,k.jsx)(w,{})]})}),(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)(y,{}),` Update Profile`]})})]})})]})}export{A as ProfileIndex};
//# sourceMappingURL=profile-DiV60L50.js.map