import{aj as A,c6 as T,al as f,c4 as k,cn as c,r as a,bd as w,bp as E,dp as P,aE as F,az as _,aA as q,j as e,bB as B,B as r,bK as G,e as I,aM as Q,aZ as n,cb as p,aG as l,s as y,bC as $,m as O,bD as z}from"./index-dP1W1_bd.js";import{c as K,e as W,r as Z}from"./utils-BPA-fYzf.js";const H=A().shape({remoteGroup:T().of(f()).min(1).label("Remote Group").required(),projectName:f().label("Project").required(),projectRole:k().oneOf([c.DATA_OWNER,c.DATA_SCIENTIST]).label("Role").required()}),R={remoteGroup:[],projectName:"",projectRole:c.DATA_SCIENTIST},J=()=>{const[u,d]=a.useState(""),C=w(u,500),{data:M=[],isFetching:N}=K(C),{data:m,isLoading:X}=E("ldap_groups_search_filter"),{data:S=[],isLoading:D}=P();a.useLayoutEffect(()=>{d(m??"")},[m]);const[j,{isLoading:v}]=W(),g=F(),h=_({defaultValues:R,resolver:q(H),reValidateMode:"onSubmit"}),{register:x,handleSubmit:L,setValue:s,getValues:o,reset:b,formState:{errors:i}}=h,V=a.useCallback(async t=>{"error"in await j({data:{projectName:t.projectName,remoteGroup:t.remoteGroup,projectRole:t.projectRole}})||(b(R),g.success({title:"Created",content:"Mapping created"}))},[j,g,b]);return e.jsx(B,{...h,children:e.jsxs(r,{flexDirection:"column",children:[e.jsx(G,{mb:"10px",children:"Remote group"}),e.jsxs(r,{mb:"20px",alignItems:"center",children:[e.jsx(I,{mr:"10px",width:"400px",children:e.jsx(Q,{placeholder:"filter query",value:u,onChange:t=>d(t.target.value),width:"100%"})}),e.jsx(G,{width:"30px",children:"->"}),e.jsx(n,{noDataMessage:"No group found",value:o("remoteGroup"),options:M,placeholder:"pick remote groups",isLoading:N,preventAdding:!0,onChange:t=>{s("remoteGroup",t,{shouldValidate:!0,shouldDirty:!0}),x("remoteGroup")},...p("remoteGroup",i)})]}),e.jsxs(r,{mb:"80px",gap:"20px",children:[e.jsx(n,{isMulti:!1,preventAdding:!0,label:"Project",noDataMessage:"No project found",value:o("projectName")?[o("projectName")]:[],options:S.map(t=>t.name)??[],placeholder:"pick a project",isLoading:D,onChange:([t])=>{s("projectName",t,{shouldValidate:!0,shouldDirty:!0}),x("projectName")},...p("projectName",i)}),e.jsx(n,{isMulti:!1,preventAdding:!0,label:"Role",value:o("projectRole")?[o("projectRole")]:[],options:Z.map(t=>t.key),placeholder:"pick a role",onChange:([t])=>{s("projectRole",t,{shouldValidate:!0,shouldDirty:!0})},...p("projectRole",i)})]}),e.jsxs(r,{justifyContent:"right",gap:"20px",children:[e.jsx(l,{type:"button",intent:"secondary",href:y.settings.remoteGroupToProjectMapping.list,children:"Back"}),e.jsx(l,{type:"button",isLoading:v,onClick:L(V),children:"Create mapping"})]})]})})},U=a.memo(J),oe=()=>($(z.projetcMapping),e.jsxs(r,{flexGrow:1,flexDirection:"column",children:[e.jsx(l,{mb:"20px",pl:"0px",width:"150px",intent:"inline",href:y.settings.remoteGroupToProjectMapping.list,children:"<- all mappings"}),e.jsx(O,{title:"Create new mapping",children:e.jsx(U,{})})]}));export{oe as default};
