import{r as a,aZ as V,cG as A,dP as P,by as k,aC as w,aD as F,dO as c,ar as E,j as e,bv as _,$ as r,bF as f,L as $,b2 as I,bG as n,ch as p,b1 as l,q as y,cb as q,au as G,ca as Q,bw as O,bx as B,b as J}from"./index-46ma1THH.js";import{c as W,e as Z,r as z}from"./utils-DMrJxpVL.js";const H=E().shape({remoteGroup:Q().of(G()).min(1).label("Remote Group").required(),projectName:G().label("Project").required(),projectRole:q().oneOf([c.DATA_OWNER,c.DATA_SCIENTIST]).label("Role").required()}),R={remoteGroup:[],projectName:"",projectRole:c.DATA_SCIENTIST},K=()=>{const[u,d]=a.useState(""),C=V(u,500),{data:M=[],isFetching:N}=W(C),{data:m,isLoading:X}=A("ldap_groups_search_filter"),{data:S=[],isLoading:D}=P();a.useLayoutEffect(()=>{d(m??"")},[m]);const[j,{isLoading:L}]=Z(),g=k(),h=w({defaultValues:R,resolver:F(H),reValidateMode:"onSubmit"}),{register:x,handleSubmit:v,setValue:s,getValues:o,reset:b,formState:{errors:i}}=h,T=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(_,{...h,children:e.jsxs(r,{flexDirection:"column",children:[e.jsx(f,{mb:"10px",children:"Remote group"}),e.jsxs(r,{mb:"20px",alignItems:"center",children:[e.jsx($,{mr:"10px",width:"400px",children:e.jsx(I,{placeholder:"filter query",value:u,onChange:t=>d(t.target.value),width:"100%"})}),e.jsx(f,{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:L,onClick:v(T),children:"Create mapping"})]})]})})},U=a.memo(K),oe=()=>(O(B.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(J,{title:"Create new mapping",children:e.jsx(U,{})})]}));export{oe as default};
