import{r as o,j as e}from"./vendor-react-wBh_31cN.js";import{$ as C,aV as y,bk as L,aq as b,R as x,G as T,ar as g,bl as p,J as U,av as u}from"./index-BKr2rJhV.js";import{u as S}from"./useTitle-DQo_L6Ox.js";import{t as E}from"./titles-CzjGGAB3.js";import{u as k}from"./index.esm-CAGtek53.js";import{o as w}from"./yup-XkUC3UEH.js";import{j as F}from"./vendor-redux-CJZrIb6x.js";import{t as P}from"./toast-3g7Fh-a0.js";import{A as R}from"./avatar-U0jpGcgI.js";import{I as h}from"./input-H6_qmzms.js";import{L as j}from"./label-Dnebucx5.js";import{C as q,a as A,b as D,c as V}from"./card-DISTA6Ay.js";import"./vendor-router-D1GqFWiT.js";import"./vendor-utils-OeoE2qq_.js";import"./vendor-icons-BUUmD6ht.js";import"./vendor-radix-BRyWS4bQ.js";import"./vendor-grid-CeFlDWv4.js";import"./tooltip-Da8-EbK8.js";const _=g().shape({firstname:p.label("First name"),lastname:p.label("Last name")}),z=({user:a})=>{const r=F(),{isServiceUser:l}=C(),{data:c,isLoading:m}=y("saas_profile_url",{skip:!l}),[i,d]=o.useState({firstname:!1,lastname:!1}),{formState:{errors:s},register:f,handleSubmit:N}=k({defaultValues:{firstname:a.firstname,lastname:a.lastname},shouldUnregister:!1,resolver:w(_),reValidateMode:"onChange",mode:"onChange"}),n=a.accountType!==L.M_ACCOUNT_TYPE,v=o.useCallback(async t=>{await r.auth.updateData({data:t}),P.success("Info updated",{description:"Your information has been successfully updated."})},[r.auth]);return o.useEffect(()=>{l&&!m&&(window.location.href=c||"https://managed.hopsworks.ai/settings")},[c,m,l]),!a.email||m?e.jsx(b,{}):l?null:e.jsxs(q,{className:"w-full",children:[e.jsx(A,{children:e.jsx(D,{children:"Edit profile"})}),e.jsxs(V,{className:"flex flex-col",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx(R,{firstName:a.firstname,lastName:a.lastname,size:"lg",editable:!0}),e.jsxs("div",{className:"flex flex-col ml-5 mt-[3px]",children:[e.jsx(x,{bold:!0,gray:!0,sm:!0,className:"mb-[3px]",children:"Username"}),e.jsx("span",{className:"text-sm font-semibold text-quartz-primary",children:a.username})]}),e.jsxs("div",{className:"flex flex-col ml-5 mt-[3px]",children:[e.jsx(x,{bold:!0,gray:!0,sm:!0,className:"mb-[3px]",children:"Email"}),e.jsx("span",{className:"text-sm font-semibold text-quartz-primary",children:a.email})]})]}),e.jsxs("div",{className:"flex mt-[30px] gap-5",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx(j,{className:"mb-1.5",children:"First name"}),e.jsx(h,{...f("firstname"),disabled:n,placeholder:"First name",onChange:t=>d({...i,firstname:a.firstname!==t.target.value}),"aria-invalid":!!s.firstname}),s.firstname&&e.jsx("p",{className:"text-xs text-destructive mt-1",children:s.firstname.message})]}),e.jsxs("div",{className:"flex-1",children:[e.jsx(j,{className:"mb-1.5",children:"Last name"}),e.jsx(h,{...f("lastname"),disabled:n,placeholder:"Last name",onChange:t=>d({...i,lastname:a.lastname!==t.target.value}),"aria-invalid":!!s.lastname}),s.lastname&&e.jsx("p",{className:"text-xs text-destructive mt-1",children:s.lastname.message})]})]}),!n&&e.jsx(T,{disabled:!i.firstname&&!i.lastname,onClick:N(v),className:"self-end mt-5",children:"Save"})]})]})},re=g().shape({name:u.label("Name"),login:u.label("Description")}),le=()=>{S(E.accountSettings);const{currentData:a,isLoading:r}=U();return r?e.jsx(b,{}):e.jsx("div",{className:"flex flex-col items-center",children:e.jsx(z,{user:a})})};export{le as default,re as schema};
