import{r as o,aR as C,j as e,a$ as I,g as P,e as S,O as N,a7 as A,cx as b,a9 as i,bI as j,fw as T,dr as p,l as G,am as $,an as _,a as u,aG as d,ax as m,b3 as f,aH as U,aT as k,aX as q,K as v,aY as M}from"./index-d6499a22.js";import{P as B,p as K,c as J,q as Q,r as Y,s as z,t as W,v as Z}from"./userUtils-59cf4f0b.js";const ee=({password:a,isOpenPopup:t,handleTogglePopup:r,onAddAnother:c})=>{const h=C();return e.jsx(I,{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(N,{pb:"20px",children:e.jsx(B,{password:a})})})},se=o.memo(ee),ae=A().shape({firstname:b.label("First name"),lastname:b.label("Last name"),email:i().email().required().label("Email address"),type:j().oneOf(T).label("User type"),role:j().oneOf([p.HOPS_ADMIN,p.HOPS_USER,p.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]=G(),[c,h]=o.useState(""),[x,{isLoading:D}]=K(),{data:L,isLoading:ne}=J(),y={firstname:"",lastname:"",email:"",role:p.HOPS_USER,type:"Hopsworks",uuid:""},{formState:{errors:n},register:l,handleSubmit:E,watch:H,setValue:g,reset:R}=$({defaultValues:y,resolver:_(ae),shouldUnregister:!1,reValidateMode:"onChange",mode:"onBlur"}),[F,w]=H(["role","type"]),O=o.useCallback(async s=>{x({givenName:s.firstname,surname:s.lastname,email:s.email,role:s.role,accountType:Q(s.type),type:Y(s.type),uuid:s.uuid}).unwrap().then(X=>{h(X.password),r()})},[x,r]),V=()=>{R(y),r()};return e.jsxs(e.Fragment,{children:[e.jsx(se,{password:c,isOpenPopup:t,handleTogglePopup:r,onAddAnother:V}),e.jsxs(u,{flexDirection:"column",children:[e.jsxs(u,{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=>{g("type",s,{shouldValidate:!0,shouldDirty:!0})},options:T,value:w,flexDirection:"row"}),w==="Hopsworks"?e.jsxs(e.Fragment,{children:[e.jsx(f,{mb:10,mt:20,children:"Cluster role"}),e.jsx(U,{mr:"8px",onChange:s=>{g("role",z(s),{shouldValidate:!0,shouldDirty:!0})},options:W(L),value:Z(F),flexDirection:"row"})]}):e.jsx(d,{width:"395px",label:"UUID",labelProps:{mt:"20px"},...l("uuid"),placeholder:"XXXXXXX",...m("uuid",n)}),e.jsx(u,{justifyContent:"right",children:e.jsx(k,{type:"button",onClick:E(O),isLoading:D,children:a?"Save":"Create new user"})})]})]})},te=o.memo(re),oe=()=>{q(M.UserManagement);const a=C();return e.jsxs(u,{flexGrow:1,flexDirection:"column",children:[e.jsx(k,{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};
