import{r as o,bw as P,j as e,bE as q,q as k,s as E,e as G,aj as I,cE as g,al as i,c4 as j,de as S,da as p,h as f,ba as O,c as $,az as v,aA as B,B as u,aM as m,b8 as d,bK as U,bn as C,aG as T,bC as M,m as _,bD as z}from"./index-dP1W1_bd.js";import{P as J,p as K,c as Q,q as W,r as Y,s as Z,t as ee,v as se}from"./userUtils-B_wRgjSC.js";import{c as ae}from"./complement-D_Q2yZKt.js";import"./where-Dy55ClhW.js";import"./useCopyToClipboard-DTBM3H3Z.js";const re=({password:r,isOpenPopup:t,handleTogglePopup:a,onAddAnother:c})=>{const h=P();return e.jsx(q,{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:()=>a(!t),mainButtonProps:{children:"Go to user list",onClick:()=>{h(k(E.settings.users.list)),a(!t)}},secondaryButtonProps:{children:"Add another user",onClick:c},children:e.jsx(G,{pb:"20px",children:e.jsx(J,{password:r})})})},te=o.memo(re),oe=I().shape({firstname:g.label("First name"),lastname:g.label("Last name"),email:i().email().required().label("Email address"),type:j().oneOf(S).label("User type"),role:j().oneOf([p.HOPS_ADMIN,p.HOPS_USER,p.HOPS_SERVICE_USER]).label("Cluster role").when("type",{is:"Hopsworks",then:f(i().required())}),uuid:i().label("UUID").when("type",{is:ae(O("Hopsworks")),then:f(i().required())})}),ne=({isEdit:r})=>{const[t,a]=$(),[c,h]=o.useState(""),[x,{isLoading:D}]=K(),{data:L,isLoading:me}=Q(),y={firstname:"",lastname:"",email:"",role:p.HOPS_USER,type:"Hopsworks",uuid:""},{formState:{errors:n},register:l,handleSubmit:F,watch:H,setValue:b,reset:R}=v({defaultValues:y,resolver:B(oe),shouldUnregister:!1,reValidateMode:"onChange",mode:"onBlur"}),[V,w]=H(["role","type"]),N=o.useCallback(async s=>{x({givenName:s.firstname,surname:s.lastname,email:s.email,role:s.role,accountType:W(s.type),type:Y(s.type),uuid:s.uuid}).unwrap().then(X=>{h(X.password),a()})},[x,a]),A=()=>{R(y),a()};return e.jsxs(e.Fragment,{children:[e.jsx(te,{password:c,isOpenPopup:t,handleTogglePopup:a,onAddAnother:A}),e.jsxs(u,{flexDirection:"column",children:[e.jsxs(u,{mb:"20px",children:[e.jsx(m,{width:"260px",label:"First Name",labelProps:{mr:"20px"},...l("firstname"),placeholder:"John",...d("firstname",n)}),e.jsx(m,{width:"260px",label:"Last Name",labelProps:{mr:"20px"},...l("lastname"),placeholder:"Tukey",...d("lastname",n)}),e.jsx(m,{width:"395px",label:"Email address",...l("email"),placeholder:"john@tukey.com",...d("email",n)})]}),e.jsx(U,{mb:10,children:"User type"}),e.jsx(C,{mr:"8px",onChange:s=>{b("type",s,{shouldValidate:!0,shouldDirty:!0})},options:S,value:w,flexDirection:"row"}),w==="Hopsworks"?e.jsxs(e.Fragment,{children:[e.jsx(U,{mb:10,mt:20,children:"Cluster role"}),e.jsx(C,{mr:"8px",onChange:s=>{b("role",Z(s),{shouldValidate:!0,shouldDirty:!0})},options:ee(L),value:se(V),flexDirection:"row"})]}):e.jsx(m,{width:"395px",label:"UUID",labelProps:{mt:"20px"},...l("uuid"),placeholder:"XXXXXXX",...d("uuid",n)}),e.jsx(u,{justifyContent:"right",children:e.jsx(T,{type:"button",onClick:F(N),isLoading:D,children:r?"Save":"Create new user"})})]})]})},le=o.memo(ne),ie=()=>{M(z.UserManagement);const r=P();return e.jsxs(u,{flexGrow:1,flexDirection:"column",children:[e.jsx(T,{mb:"20px",pl:"0px",intent:"inline",onClick:()=>r(k(E.settings.users.list)),children:"<- all users"}),e.jsx(_,{title:"Create new user",children:e.jsx(le,{isEdit:!1})})]})},xe=o.memo(ie);export{xe as default};
