import{r as s,dQ as D,bz as y,dO as d,aC as L,aD as G,ar as k,dP as n,j as e,bw as H,a as c,aZ as b,ci as x,bH as f,aJ as S,t as O,cc as N,au as A,cb as w,bx as F,by as W,c_ as I,W as K,bk as $,D as V}from"./index-_eM6l4Nf.js";import{c as _,H as q,O as B,L as U}from"./HWMappingForm-Ctet_-Ub.js";import{u as Q}from"./useProjectRoleOptions-Qx6gDtUz.js";import"./index-HeUA1Nop.js";import"./where-B0yrqZx2.js";const z=k().shape({group:w().of(A()).min(1).label("Group").required(),projectName:A().label("Project").required(),projectRole:N().oneOf([d.DATA_OWNER,d.DATA_SCIENTIST,d.OBSERVER]).label("Role").required()}),J=({groupType:a})=>{const[l,{isLoading:g}]=_(),{data:u=[],isLoading:p}=D(),m=Q(),r=y(),i=s.useMemo(()=>({group:[],projectName:"",projectRole:d.DATA_SCIENTIST,groupType:a}),[a]),M=L({defaultValues:i,resolver:G(z),reValidateMode:"onSubmit"}),{register:P,handleSubmit:R,reset:C,control:j,formState:{errors:h}}=M,E=s.useCallback(async t=>{"error"in await l({data:{projectName:t.projectName,group:t.group,projectRole:t.projectRole,groupType:a}})||(C(i),r.success({title:"Created",content:"Mapping created"}))},[l,i,a,r,C]),T=()=>null,v={[n.LDAP]:U,[n.OAUTH]:B,[n.HOPSWORKS]:q}[a]||T;return e.jsxs(H,{...M,children:[e.jsxs(c,{flexDirection:"column",children:[e.jsx(b,{name:"group",control:j,render:({field:t})=>e.jsx(v,{isEdit:!0,value:t.value?[]:t.value,onChange:o=>{t.onChange(o),P("group")},...x("group",h)})}),e.jsxs(c,{gap:"20px",children:[e.jsx(b,{name:"projectName",control:j,render:({field:t})=>e.jsx(f,{isMulti:!1,preventAdding:!0,label:"Project",noDataMessage:"No project found",value:t.value?[t.value]:[],options:u.map(o=>o.name)??[],placeholder:"pick a project",isLoading:p,onChange:([o])=>t.onChange(o),...x("projectName",h)})}),e.jsx(b,{name:"projectRole",control:j,render:({field:t})=>e.jsx(f,{isMulti:!1,preventAdding:!0,label:"Role",value:t.value?[t.value]:[],options:m.map(o=>o),placeholder:"pick a role",onChange:([o])=>t.onChange(o),...x("projectRole",h)})})]})]}),e.jsxs(c,{justifyContent:"right",mt:"20px",gap:"20px",children:[e.jsx(S,{type:"button",intent:"secondary",href:O.settings.groupToProjectMapping.list,children:"Back"}),e.jsx(S,{type:"button",isLoading:g,onClick:R(E),children:"Create mapping"})]})]})},Z=s.memo(J),oe=()=>{F(W.projetcMapping);const{data:a}=I(),[l,g]=s.useState(0),[u,p]=s.useState(),m=i=>({Hopsworks:n.HOPSWORKS,"LDAP/Kerberos":n.LDAP,OAuth:n.OAUTH})[i],r=s.useMemo(()=>[...a.hwGroupMappingSyncEnabled?[{title:"Hopsworks",onClick:()=>p(n.HOPSWORKS)}]:[],...a.ldapGroupMappingSyncEnabled?[{title:"LDAP/Kerberos",onClick:()=>p(n.LDAP)}]:[],...a.oauthGroupMappingSyncEnabled?[{title:"OAuth",onClick:()=>p(n.OAUTH)}]:[]],[a.hwGroupMappingSyncEnabled,a.ldapGroupMappingSyncEnabled,a.oauthGroupMappingSyncEnabled]);return s.useEffect(()=>{r[0]&&p(m(r[0].title))},[r]),e.jsxs(c,{flexGrow:1,flexDirection:"column",children:[e.jsx(S,{mb:"20px",pl:"0px",width:"150px",intent:"inline",href:O.settings.groupToProjectMapping.list,children:"<- all mappings"}),e.jsxs(K,{title:"Create new mapping",children:[e.jsx($,{tabs:r,activeTab:l,onTabChange:g}),e.jsx(c,{mt:"20px",flexDirection:"column",children:u?e.jsx(Z,{groupType:u}):e.jsx(V,{})})]})]})};export{oe as default};
