import{r as x,bx as P,j as e,bJ as M,F as $,t as U,x as C,w as v,dX as b,aA as z,aB as B,q as r,aH as l,aY as i,an as w,ao as g,v as y,bl as X,bf as k,d_ as L,aJ as F,Z as J,as as t,k as p,b0 as h,cq as N,d$ as Z,d9 as S,bG as K,bH as Q,f as Y}from"./index-DNBEEyYo.js";import{n as W,c as ee}from"./index-CcMvd7df.js";import{p as se}from"./form-nDhxPMre.js";import{P as te,r as re,b as ae,f as oe,c as ne,d as le}from"./userUtils-BKNbZ1ka.js";import"./where-B5BSuibK.js";import"./useCopyToClipboard-BnywFRQi.js";const ie=({password:m,isOpenPopup:u,handleTogglePopup:a,onAddAnother:j})=>{const f=P();return e.jsx(M,{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(U(C.settings.users.list)),a(!u)}},secondaryButtonProps:{children:"Add another user",onClick:j},children:e.jsx($,{pb:"20px",children:e.jsx(te,{password:m})})})},ce=x.memo(ie),me=J().shape({firstname:S.label("First name"),lastname:S.label("Last name"),email:t().email().required().label("Email address"),maxNumProjects:Z.optional().label("Max number of projects"),type:N().oneOf(L).label("User type"),role:N().oneOf([b.HOPS_ADMIN,b.HOPS_USER,b.HOPS_SERVICE_USER]).label("Cluster role").when("type",{is:"Hopsworks",then:p(t().required())}),uuid:t().label("UUID").when("type",{is:h("LDAP"),then:p(t().required())}).when("type",{is:h("Kerberos"),then:p(t().required())}),subject:t().label("subject").when("type",{is:h("OAuth2"),then:p(t().required())}),clientId:t().label("Client Id").when("type",{is:h("OAuth2"),then:p(t().required())})}),ue=({isEdit:m})=>{const[u,a]=v(),[j,f]=x.useState(""),[I,{isLoading:O}]=W(),{data:q,isLoading:xe}=ee(),A=P(),D={firstname:"",lastname:"",email:"",maxNumProjects:"-1",role:b.HOPS_USER,type:"Hopsworks",uuid:"",subject:"",clientId:""},{formState:{errors:o},register:n,handleSubmit:E,watch:H,setValue:T,reset:_}=z({defaultValues:D,resolver:B(me),shouldUnregister:!1,reValidateMode:"onChange",mode:"onBlur"}),[R,d]=H(["role","type"]),V=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(U(C.settings.users.list))})},[I,a,A]),G=()=>{_(D),a()};return e.jsxs(e.Fragment,{children:[e.jsx(ce,{password:j,isOpenPopup:u,handleTogglePopup:a,onAddAnother:G}),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(w,{mainText:"Set to -1 to use the cluster’s default maximum number of projects.",children:e.jsx(g,{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(X,{mb:10,children:"User type"}),e.jsx(k,{mr:"8px",onChange:s=>{T("type",s,{shouldValidate:!0,shouldDirty:!0})},options:L,value:d,flexDirection:"row"}),d==="Hopsworks"&&e.jsxs(e.Fragment,{children:[e.jsx(X,{mb:10,mt:20,children:"Cluster role"}),e.jsx(k,{mr:"8px",onChange:s=>{T("role",le(s),{shouldValidate:!0,shouldDirty:!0})},options:ne(q),value:oe(R),flexDirection:"row"})]}),(d==="Kerberos"||d==="LDAP")&&e.jsx(l,{labelAction:e.jsx(r,{gap:"5px",ml:"10px",children:e.jsx(w,{mainText:"entryUUID or ObjectGUID",children:e.jsx(g,{icon:y.info_block,size:"xs"})})}),width:"395px",label:"UUID",labelProps:{mt:"20px"},...n("uuid"),placeholder:"XXXXXXX",...i("uuid",o)}),d==="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(w,{mainText:"The user’s ID value returned as the subject claim in user info.",children:e.jsx(g,{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(F,{type:"button",onClick:E(V),isLoading:O,children:m?"Save":"Create new user"})})]})]})},de=x.memo(ue),pe=()=>{K(Q.UserManagement);const m=P();return e.jsxs(r,{flexGrow:1,flexDirection:"column",children:[e.jsx(F,{mb:"20px",pl:"0px",intent:"inline",onClick:()=>m(U(C.settings.users.list)),children:"<- all users"}),e.jsx(Y,{title:"Create new user",children:e.jsx(de,{isEdit:!1})})]})},ye=x.memo(pe);export{ye as default};
