import{r as o,b4 as P,j as e,be as q,o as S,q as k,c as A,ae as I,ce as g,ag as i,bF as j,cP as E,cL as p,h as f,aG as O,w as $,au as v,av as _,d as u,aR as m,aE as d,aV as U,aS as C,b6 as T,bb as M,Q as B,bc as Q}from"./index-CK33qGU_.js";import{P as J,p as z,c as K,q as W,r as Y,s as Z,t as ee,v as se}from"./userUtils-Dm7_xATn.js";import{c as ae}from"./complement-M2aUPqXA.js";import"./where-Mo9A6TUc.js";import"./useCopyToClipboard-_4vnCVip.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(S(k.settings.users.list)),a(!t)}},secondaryButtonProps:{children:"Add another user",onClick:c},children:e.jsx(A,{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(E).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:L}]=z(),{data:V,isLoading:me}=K(),b={firstname:"",lastname:"",email:"",role:p.HOPS_USER,type:"Hopsworks",uuid:""},{formState:{errors:n},register:l,handleSubmit:D,watch:F,setValue:y,reset:R}=v({defaultValues:b,resolver:_(oe),shouldUnregister:!1,reValidateMode:"onChange",mode:"onBlur"}),[H,w]=F(["role","type"]),G=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]),N=()=>{R(b),a()};return e.jsxs(e.Fragment,{children:[e.jsx(te,{password:c,isOpenPopup:t,handleTogglePopup:a,onAddAnother:N}),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=>{y("type",s,{shouldValidate:!0,shouldDirty:!0})},options:E,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=>{y("role",Z(s),{shouldValidate:!0,shouldDirty:!0})},options:ee(V),value:se(H),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:D(G),isLoading:L,children:r?"Save":"Create new user"})})]})]})},le=o.memo(ne),ie=()=>{M(Q.UserManagement);const r=P();return e.jsxs(u,{flexGrow:1,flexDirection:"column",children:[e.jsx(T,{mb:"20px",pl:"0px",intent:"inline",onClick:()=>r(S(k.settings.users.list)),children:"<- all users"}),e.jsx(B,{title:"Create new user",children:e.jsx(le,{isEdit:!1})})]})},xe=o.memo(ie);export{xe as default};
