import{ae as T,bH as A,ag as f,bF as P,bX as c,r as a,cI as k,aU as E,cZ as F,bd as w,au as Q,av as q,j as e,ba as I,d as r,aV as G,c as _,aR as $,bM as n,bN as p,b6 as l,q as y,bb as O,Q as B,bc as H}from"./index-CK33qGU_.js";import{c as J,e as U,r as W}from"./utils-B1ZrsCe9.js";const X=T().shape({remoteGroup:A().of(f()).min(1).label("Remote Group").required(),projectName:f().label("Project").required(),projectRole:P().oneOf([c.DATA_OWNER,c.DATA_SCIENTIST]).label("Role").required()}),R={remoteGroup:[],projectName:"",projectRole:c.DATA_SCIENTIST},Z=()=>{const[u,d]=a.useState(""),M=k(u,500),{data:N=[],isFetching:C}=J(M),{data:m,isLoading:K}=E("ldap_groups_search_filter"),{data:S=[],isLoading:L}=F();a.useLayoutEffect(()=>{d(m??"")},[m]);const[j,{isLoading:V}]=U(),g=w(),h=Q({defaultValues:R,resolver:q(X),reValidateMode:"onSubmit"}),{register:x,handleSubmit:v,setValue:s,getValues:o,reset:b,formState:{errors:i}}=h,D=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(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($,{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: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(l,{type:"button",intent:"secondary",href:y.settings.remoteGroupToProjectMapping.list,children:"Back"}),e.jsx(l,{type:"button",isLoading:V,onClick:v(D),children:"Create mapping"})]})]})})},z=a.memo(Z),oe=()=>(O(H.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(B,{title:"Create new mapping",children:e.jsx(z,{})})]}));export{oe as default};
