import{r as o,aS as C,j as e,b0 as X,c as P,b as S,o as A,a7 as G,cy as w,a9 as i,bJ as j,fC as k,du as u,P as O,an as _,ao as $,Q as p,aH as d,ay as m,b4 as f,aI as U,aU as E,aY as q,E as v,aZ as M}from"./index-ea7817a2.js";import{P as B,p as Q,c as J,q as Y,r as Z,s as z,t as K,v as W}from"./userUtils-d5498d6e.js";const ee=({password:a,isOpenPopup:t,handleTogglePopup:r,onAddAnother:c})=>{const h=C();return e.jsx(X,{title:"Temporary user password",secondaryText:`A temporary user password has been generated. It is strongly
          recommended to ask the user to generate a new one.`,isOpen:t,onClose:()=>r(!t),mainButtonProps:{children:"Go to user list",onClick:()=>{h(P(S.settings.users.list)),r(!t)}},secondaryButtonProps:{children:"Add another user",onClick:c},children:e.jsx(A,{pb:"20px",children:e.jsx(B,{password:a})})})},se=o.memo(ee),ae=G().shape({firstname:w.label("First name"),lastname:w.label("Last name"),email:i().email().required().label("Email address"),type:j().oneOf(k).label("User type"),role:j().oneOf([u.HOPS_ADMIN,u.HOPS_USER,u.HOPS_SERVICE_USER]).label("Cluster role").when("type",{is:a=>a==="Hopsworks",then:i().required()}),uuid:i().label("UUID").when("type",{is:a=>a!=="Hopsworks",then:i().required()})}),re=({isEdit:a})=>{const[t,r]=O(),[c,h]=o.useState(""),[x,{isLoading:T}]=Q(),{data:D,isLoading:ne}=J(),y={firstname:"",lastname:"",email:"",role:u.HOPS_USER,type:"Hopsworks",uuid:""},{formState:{errors:n},register:l,handleSubmit:H,watch:L,setValue:b,reset:F}=_({defaultValues:y,resolver:$(ae),shouldUnregister:!1,reValidateMode:"onChange",mode:"onBlur"}),[R,g]=L(["role","type"]),V=o.useCallback(async s=>{x({givenName:s.firstname,surname:s.lastname,email:s.email,role:s.role,accountType:Y(s.type),type:Z(s.type),uuid:s.uuid}).unwrap().then(N=>{h(N.password),r()})},[x,r]),I=()=>{F(y),r()};return e.jsxs(e.Fragment,{children:[e.jsx(se,{password:c,isOpenPopup:t,handleTogglePopup:r,onAddAnother:I}),e.jsxs(p,{flexDirection:"column",children:[e.jsxs(p,{mb:"20px",children:[e.jsx(d,{width:"260px",label:"First Name",labelProps:{mr:"20px"},...l("firstname"),placeholder:"John",...m("firstname",n)}),e.jsx(d,{width:"260px",label:"Last Name",labelProps:{mr:"20px"},...l("lastname"),placeholder:"Tukey",...m("lastname",n)}),e.jsx(d,{width:"395px",label:"Email address",...l("email"),placeholder:"john@tukey.com",...m("email",n)})]}),e.jsx(f,{mb:10,children:"User type"}),e.jsx(U,{mr:"8px",onChange:s=>{b("type",s,{shouldValidate:!0,shouldDirty:!0})},options:k,value:g,flexDirection:"row"}),g==="Hopsworks"?e.jsxs(e.Fragment,{children:[e.jsx(f,{mb:10,mt:20,children:"Cluster role"}),e.jsx(U,{mr:"8px",onChange:s=>{b("role",z(s),{shouldValidate:!0,shouldDirty:!0})},options:K(D),value:W(R),flexDirection:"row"})]}):e.jsx(d,{width:"395px",label:"UUID",labelProps:{mt:"20px"},...l("uuid"),placeholder:"XXXXXXX",...m("uuid",n)}),e.jsx(p,{justifyContent:"right",children:e.jsx(E,{type:"button",onClick:H(V),isLoading:T,children:a?"Save":"Create new user"})})]})]})},te=o.memo(re),oe=()=>{q(M.UserManagement);const a=C();return e.jsxs(p,{flexGrow:1,flexDirection:"column",children:[e.jsx(E,{mb:"20px",pl:"0px",intent:"inline",onClick:()=>a(P(S.settings.users.list)),children:"<- all users"}),e.jsx(v,{title:"Create new user",children:e.jsx(te,{isEdit:!1})})]})},de=o.memo(oe);export{de as default};
