import{r as o,bp as P,j as e,bA as N,q as k,s as D,d as X,al as q,cK as g,an as i,cb as j,dn as S,dj as p,k as f,aT as O,aU as $,w as B,aD as _,aE as v,B as u,b5 as d,aR as m,bG as U,bf as C,b4 as T,bx as M,y as J,by as K}from"./index-C1DmWO_C.js";import{P as Q,p as z,c as W,q as Y,r as Z,s as ee,t as se,v as ae}from"./userUtils-BPjSh7uE.js";import"./where-C_FV43Y5.js";import"./useCopyToClipboard-v9FBn9Nz.js";const re=({password:r,isOpenPopup:t,handleTogglePopup:a,onAddAnother:c})=>{const h=P();return e.jsx(N,{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(D.settings.users.list)),a(!t)}},secondaryButtonProps:{children:"Add another user",onClick:c},children:e.jsx(X,{pb:"20px",children:e.jsx(Q,{password:r})})})},te=o.memo(re),oe=q().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:O($("Hopsworks")),then:f(i().required())})}),ne=({isEdit:r})=>{const[t,a]=B(),[c,h]=o.useState(""),[x,{isLoading:E}]=z(),{data:L,isLoading:de}=W(),y={firstname:"",lastname:"",email:"",role:p.HOPS_USER,type:"Hopsworks",uuid:""},{formState:{errors:n},register:l,handleSubmit:R,watch:F,setValue:b,reset:H}=_({defaultValues:y,resolver:v(oe),shouldUnregister:!1,reValidateMode:"onChange",mode:"onBlur"}),[V,w]=F(["role","type"]),A=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(I=>{h(I.password),a()})},[x,a]),G=()=>{H(y),a()};return e.jsxs(e.Fragment,{children:[e.jsx(te,{password:c,isOpenPopup:t,handleTogglePopup:a,onAddAnother:G}),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(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",ee(s),{shouldValidate:!0,shouldDirty:!0})},options:se(L),value:ae(V),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(T,{type:"button",onClick:R(A),isLoading:E,children:r?"Save":"Create new user"})})]})]})},le=o.memo(ne),ie=()=>{M(K.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(D.settings.users.list)),children:"<- all users"}),e.jsx(J,{title:"Create new user",children:e.jsx(le,{isEdit:!1})})]})},he=o.memo(ie);export{he as default};
