import{al as C,cT as x,bI as E,bz as L,cm as S,bh as T,r as c,aD as v,aE as w,cU as F,j as e,L as D,y as I,B as s,cE as R,bV as p,b,b5 as g,aR as j,b4 as V,cK as y,bx as k,az as N,by as _}from"./index-C1DmWO_C.js";const $=C().shape({firstname:x.label("First name"),lastname:x.label("Last name")}),z=({user:a})=>{const n=E(),m=L(),{isServiceUser:l}=S(),{data:d,isLoading:i}=T("saas_profile_url",{skip:!l}),[r,u]=c.useState({firstname:!1,lastname:!1}),{formState:{errors:f},register:h,handleSubmit:P}=v({defaultValues:{firstname:a.firstname,lastname:a.lastname},shouldUnregister:!1,resolver:w($),reValidateMode:"onChange",mode:"onChange"}),o=a.accountType!==F.M_ACCOUNT_TYPE,U=c.useCallback(async t=>{await n.auth.updateData({data:t}),m.success({title:"Info updated",content:"Your information has been successfully updated."})},[n.auth,m]);return c.useEffect(()=>{l&&!i&&(window.location.href=d||"https://managed.hopsworks.ai/settings")},[d,i,l]),!a.email||i?e.jsx(D,{}):l?null:e.jsx(I,{width:"100%",title:"Edit profile",children:e.jsxs(s,{flexDirection:"column",children:[e.jsxs(s,{children:[e.jsx(R,{firstName:a.firstname,lastName:a.lastname}),e.jsxs(s,{mt:"3px",flexDirection:"column",ml:"20px",children:[e.jsx(p,{mb:"3px",gray:!0,children:"Username"}),e.jsx(b,{primary:!0,children:a.username})]}),e.jsxs(s,{mt:"3px",flexDirection:"column",ml:"20px",children:[e.jsx(p,{mb:"3px",gray:!0,children:"Email"}),e.jsx(b,{primary:!0,children:a.email})]})]}),e.jsxs(s,{mt:"30px",children:[e.jsx(g,{label:"First name",...h("firstname"),labelProps:{mr:"20px"},disabled:o,placeholder:"First name",onChange:t=>u({...r,firstname:a.firstname!==t.target.value}),...j("firstname",f)}),e.jsx(g,{label:"Last name",...h("lastname"),disabled:o,labelProps:{mr:"20px"},placeholder:"Last name",onChange:t=>u({...r,lastname:a.lastname!==t.target.value}),...j("lastname",f)})]}),!o&&e.jsx(V,{disabled:!r.firstname&&!r.lastname,onClick:P(U),mt:"20px",alignSelf:"flex-end",children:"Save"})]})})},B=C().shape({name:y.label("Name"),login:y.label("Description")}),G=()=>{k(_.accountSettings);const{currentData:a,isLoading:n}=N();return n?e.jsx(D,{}):e.jsx(s,{flexDirection:"column",alignItems:"center",children:e.jsx(z,{user:a})})};export{G as default,B as schema};
