import{r as x,bo as U,j as e,bA as $,L as M,s as P,t as C,y as v,dE as b,aC as z,aD as B,ar as J,a as r,aH as l,aY as i,ao as g,ap as w,d as y,bG as k,be as S,dH as N,aJ as E,au as t,cc as X,dI as W,cY as L,m as d,a$ as h,bx as K,by as Y,W as Q}from"./index-_eM6l4Nf.js";import{n as Z,c as ee}from"./index-HeUA1Nop.js";import{p as se}from"./form-CMT9TYED.js";import{P as te,r as re,b as ae,f as oe,c as ne,d as le}from"./userUtils-DvjgeLmw.js";import"./where-B0yrqZx2.js";import"./useCopyToClipboard-BUvZjse8.js";const ie=({password:m,isOpenPopup:u,handleTogglePopup:a,onAddAnother:j})=>{const f=U();return e.jsx($,{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:u,onClose:()=>a(!u),mainButtonProps:{children:"Go to user list",onClick:()=>{f(P(C.settings.users.list)),a(!u)}},secondaryButtonProps:{children:"Add another user",onClick:j},children:e.jsx(M,{pb:"20px",children:e.jsx(te,{password:m})})})},ce=x.memo(ie),me=J().shape({firstname:L.label("First name"),lastname:L.label("Last name"),email:t().email().required().label("Email address"),maxNumProjects:W.optional().label("Max number of projects"),type:X().oneOf(N).label("User type"),role:X().oneOf([b.HOPS_ADMIN,b.HOPS_USER,b.HOPS_SERVICE_USER]).label("Cluster role").when("type",{is:"Hopsworks",then:d(t().required())}),uuid:t().label("UUID").when("type",{is:h("LDAP"),then:d(t().required())}).when("type",{is:h("Kerberos"),then:d(t().required())}),subject:t().label("subject").when("type",{is:h("OAuth2"),then:d(t().required())}),clientId:t().label("Client Id").when("type",{is:h("OAuth2"),then:d(t().required())})}),ue=({isEdit:m})=>{const[u,a]=v(),[j,f]=x.useState(""),[I,{isLoading:O}]=Z(),{data:H,isLoading:xe}=ee(),A=U(),D={firstname:"",lastname:"",email:"",maxNumProjects:"-1",role:b.HOPS_USER,type:"Hopsworks",uuid:"",subject:"",clientId:""},{formState:{errors:o},register:n,handleSubmit:_,watch:F,setValue:T,reset:R}=z({defaultValues:D,resolver:B(me),shouldUnregister:!1,reValidateMode:"onChange",mode:"onBlur"}),[V,p]=F(["role","type"]),G=x.useCallback(async s=>{I({givenName:s.firstname,surname:s.lastname,email:s.email,maxNumProjects:s.maxNumProjects,role:s.role,accountType:ae(s.type),type:re(s.type),uuid:s.uuid,subject:s.subject,clientId:s.clientId}).unwrap().then(c=>{c!=null&&c.password?(f(c==null?void 0:c.password),a()):A(P(C.settings.users.list))})},[I,a,A]),q=()=>{R(D),a()};return e.jsxs(e.Fragment,{children:[e.jsx(ce,{password:j,isOpenPopup:u,handleTogglePopup:a,onAddAnother:q}),e.jsxs(r,{flexDirection:"column",children:[e.jsxs(r,{mb:"20px",gap:"10px",children:[e.jsx(l,{width:"260px",label:"First Name",labelProps:{mr:"20px"},...n("firstname"),placeholder:"John",...i("firstname",o)}),e.jsx(l,{width:"260px",label:"Last Name",labelProps:{mr:"20px"},...n("lastname"),placeholder:"Tukey",...i("lastname",o)}),e.jsx(l,{width:"395px",label:"Email address",...n("email"),placeholder:"john@tukey.com",...i("email",o)}),e.jsx(l,{labelAction:e.jsx(r,{gap:"5px",ml:"10px",children:e.jsx(g,{mainText:"Set to -1 to use the cluster’s default maximum number of projects.",children:e.jsx(w,{icon:y.info_block,size:"xs"})})}),placeholder:"",type:"number",step:"1",label:"Max number of projects",...n("maxNumProjects",{valueAsNumber:!0,setValueAs:se(-1)}),...i("maxNumProjects",o)})]}),e.jsx(k,{mb:10,children:"User type"}),e.jsx(S,{mr:"8px",onChange:s=>{T("type",s,{shouldValidate:!0,shouldDirty:!0})},options:N,value:p,flexDirection:"row"}),p==="Hopsworks"&&e.jsxs(e.Fragment,{children:[e.jsx(k,{mb:10,mt:20,children:"Cluster role"}),e.jsx(S,{mr:"8px",onChange:s=>{T("role",le(s),{shouldValidate:!0,shouldDirty:!0})},options:ne(H),value:oe(V),flexDirection:"row"})]}),(p==="Kerberos"||p==="LDAP")&&e.jsx(l,{labelAction:e.jsx(r,{gap:"5px",ml:"10px",children:e.jsx(g,{mainText:"entryUUID or ObjectGUID",children:e.jsx(w,{icon:y.info_block,size:"xs"})})}),width:"395px",label:"UUID",labelProps:{mt:"20px"},...n("uuid"),placeholder:"XXXXXXX",...i("uuid",o)}),p==="OAuth2"&&e.jsxs(r,{flexDirection:"row",gap:"10px",children:[e.jsx(l,{width:"395px",label:"Client Id",labelProps:{mt:"20px"},...n("clientId"),placeholder:"XXXXXXXX",...i("clientId",o)}),e.jsx(l,{labelAction:e.jsx(r,{gap:"5px",ml:"10px",children:e.jsx(g,{mainText:"The user’s ID value returned as the subject claim in user info.",children:e.jsx(w,{icon:y.info_block,size:"xs"})})}),width:"395px",label:"Subject",labelProps:{mt:"20px"},...n("subject"),placeholder:"subject",...i("subject",o)})]}),e.jsx(r,{justifyContent:"right",children:e.jsx(E,{type:"button",onClick:_(G),isLoading:O,children:m?"Save":"Create new user"})})]})]})},pe=x.memo(ue),de=()=>{K(Y.UserManagement);const m=U();return e.jsxs(r,{flexGrow:1,flexDirection:"column",children:[e.jsx(E,{mb:"20px",pl:"0px",intent:"inline",onClick:()=>m(P(C.settings.users.list)),children:"<- all users"}),e.jsx(Q,{title:"Create new user",children:e.jsx(pe,{isEdit:!1})})]})},ye=x.memo(de);export{ye as default};
