import{a7 as A,bK as V,a9 as b,bI as k,fA as l,r as a,fH as P,aK as w,fD as E,aZ as F,am as I,an as Q,j as e,aW as _,a as r,b3 as G,O,aG as q,bP as n,bQ as p,aT as c,e as y,aX as K,K as $,aY as B}from"./index-d6499a22.js";import{c as W,e as H,r as J}from"./utils-b8e6cf24.js";const X=A().shape({remoteGroup:V().of(b()).min(1).label("Remote Group").required(),projectName:b().label("Project").required(),projectRole:k().oneOf([l.DATA_OWNER,l.DATA_SCIENTIST]).label("Role").required()}),R={remoteGroup:[],projectName:"",projectRole:l.DATA_SCIENTIST},Y=()=>{const[u,d]=a.useState(""),M=P(u,500),{data:N=[],isFetching:C}=W(M),{data:m,isLoading:z}=w("ldap_groups_search_filter"),{data:S=[],isLoading:D}=E();a.useLayoutEffect(()=>{d(m??"")},[m]);const[j,{isLoading:L}]=H(),g=F(),h=I({defaultValues:R,resolver:Q(X),reValidateMode:"onSubmit"}),{register:x,handleSubmit:T,setValue:s,getValues:o,reset:f,formState:{errors:i}}=h,v=a.useCallback(async t=>{"error"in await j({data:{projectName:t.projectName,remoteGroup:t.remoteGroup,projectRole:t.projectRole}})||(f(R),g.success({title:"Created",content:"Mapping created"}))},[j,g,f]);return e.jsx(_,{...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(O,{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:N,placeholder:"pick remote groups",isLoading:C,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:J.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(c,{type:"button",intent:"secondary",href:y.settings.remoteGroupToProjectMapping.list,children:"Back"}),e.jsx(c,{type:"button",isLoading:L,onClick:T(v),children:"Create mapping"})]})]})})},Z=a.memo(Y),oe=()=>(K(B.projetcMapping),e.jsxs(r,{flexGrow:1,flexDirection:"column",children:[e.jsx(c,{mb:"20px",pl:"0px",width:"150px",intent:"inline",href:y.settings.remoteGroupToProjectMapping.list,children:"<- all mappings"}),e.jsx($,{title:"Create new mapping",children:e.jsx(Z,{})})]}));export{oe as default};
