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