import{al as V,cd as w,an as f,cb as A,cs as c,r as a,b0 as P,bh as k,dw as E,bz as F,aD as I,aE as _,j as e,bw as Q,B as r,bG as G,d as $,b5 as q,bH as n,ci as p,b4 as l,s as R,bx as B,y as O,by as H}from"./index-C1DmWO_C.js";import{c as z,e as J,r as W}from"./utils-JD3SOAYH.js";const K=V().shape({remoteGroup:w().of(f()).min(1).label("Remote Group").required(),projectName:f().label("Project").required(),projectRole:A().oneOf([c.DATA_OWNER,c.DATA_SCIENTIST]).label("Role").required()}),y={remoteGroup:[],projectName:"",projectRole:c.DATA_SCIENTIST},U=()=>{const[u,d]=a.useState(""),M=P(u,500),{data:N=[],isFetching:C}=z(M),{data:m,isLoading:Y}=k("ldap_groups_search_filter"),{data:D=[],isLoading:S}=E();a.useLayoutEffect(()=>{d(m??"")},[m]);const[j,{isLoading:v}]=J(),g=F(),h=I({defaultValues:y,resolver:_(K),reValidateMode:"onSubmit"}),{register:x,handleSubmit:L,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(y),g.success({title:"Created",content:"Mapping created"}))},[j,g,b]);return e.jsx(Q,{...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: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:D.map(t=>t.name)??[],placeholder:"pick a project",isLoading:S,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:R.settings.remoteGroupToProjectMapping.list,children:"Back"}),e.jsx(l,{type:"button",isLoading:v,onClick:L(T),children:"Create mapping"})]})]})})},X=a.memo(U),oe=()=>(B(H.projetcMapping),e.jsxs(r,{flexGrow:1,flexDirection:"column",children:[e.jsx(l,{mb:"20px",pl:"0px",width:"150px",intent:"inline",href:R.settings.remoteGroupToProjectMapping.list,children:"<- all mappings"}),e.jsx(O,{title:"Create new mapping",children:e.jsx(X,{})})]}));export{oe as default};
