import{a7 as T,bL as A,a9 as b,bJ as E,fG as l,r as a,fN as P,aL as k,fJ as Q,a_ as w,an as F,ao as _,j as e,aX as I,Q as r,b4 as G,o as $,aH as q,bQ as n,bR as p,aU as c,b as y,aY as J,E as O,aZ as B}from"./index-ea7817a2.js";import{c as H,e as U,r as W}from"./utils-c5922439.js";const X=T().shape({remoteGroup:A().of(b()).min(1).label("Remote Group").required(),projectName:b().label("Project").required(),projectRole:E().oneOf([l.DATA_OWNER,l.DATA_SCIENTIST]).label("Role").required()}),R={remoteGroup:[],projectName:"",projectRole:l.DATA_SCIENTIST},Y=()=>{const[u,d]=a.useState(""),N=P(u,500),{data:M=[],isFetching:C}=H(N),{data:m,isLoading:z}=k("ldap_groups_search_filter"),{data:S=[],isLoading:L}=Q();a.useLayoutEffect(()=>{d(m??"")},[m]);const[j,{isLoading:D}]=U(),g=w(),h=F({defaultValues:R,resolver:_(X),reValidateMode:"onSubmit"}),{register:x,handleSubmit:V,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(I,{...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($,{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: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:L,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:W.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:D,onClick:V(v),children:"Create mapping"})]})]})})},Z=a.memo(Y),oe=()=>(J(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(O,{title:"Create new mapping",children:e.jsx(Z,{})})]}));export{oe as default};
