import{r as s,e6 as L,bI as D,cz as c,aA as G,aB as k,e5 as n,j as e,bF as y,q as l,aZ as x,cv as b,bP as f,aJ as S,x as E,Z as H,cq as N,as as A,co as F,bG as w,bH as q,d7 as I,f as K,bt as W,L as _}from"./index-DNBEEyYo.js";import{c as $,H as B,O as U,L as V}from"./HWMappingForm-CwFWWVv6.js";import{u as Z}from"./useProjectRoleOptions-BHGB8WQ7.js";import"./index-CcMvd7df.js";import"./where-B5BSuibK.js";const z=H().shape({group:F().of(A()).min(1).label("Group").required(),projectName:A().label("Project").required(),projectRole:N().oneOf([c.DATA_OWNER,c.DATA_SCIENTIST,c.OBSERVER,c.FEATURE_STORE_RESTRICTED]).label("Role").required()}),J=({groupType:o})=>{const[u,{isLoading:g}]=$(),{data:d=[],isLoading:p}=L(),m=Z(),r=D(),i=s.useMemo(()=>({group:[],projectName:"",projectRole:c.DATA_SCIENTIST,groupType:o}),[o]),M=G({defaultValues:i,resolver:k(z),reValidateMode:"onSubmit"}),{register:R,handleSubmit:T,reset:C,control:j,formState:{errors:h}}=M,O=s.useCallback(async t=>{"error"in await u({data:{projectName:t.projectName,group:t.group,projectRole:t.projectRole,groupType:o}})||(C(i),r.success({title:"Created",content:"Mapping created"}))},[u,i,o,r,C]),P=()=>null,v={[n.LDAP]:V,[n.OAUTH]:U,[n.HOPSWORKS]:B}[o]||P;return e.jsxs(y,{...M,children:[e.jsxs(l,{flexDirection:"column",children:[e.jsx(x,{name:"group",control:j,render:({field:t})=>e.jsx(v,{isEdit:!0,value:t.value?[]:t.value,onChange:a=>{t.onChange(a),R("group")},...b("group",h)})}),e.jsxs(l,{gap:"20px",children:[e.jsx(x,{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:d.map(a=>a.name)??[],placeholder:"pick a project",isLoading:p,onChange:([a])=>t.onChange(a),...b("projectName",h)})}),e.jsx(x,{name:"projectRole",control:j,render:({field:t})=>e.jsx(f,{isMulti:!1,preventAdding:!0,label:"Role",value:t.value?[t.value]:[],options:m.map(a=>a),placeholder:"pick a role",onChange:([a])=>t.onChange(a),...b("projectRole",h)})})]})]}),e.jsxs(l,{justifyContent:"right",mt:"20px",gap:"20px",children:[e.jsx(S,{type:"button",intent:"secondary",href:E.settings.groupToProjectMapping.list,children:"Back"}),e.jsx(S,{type:"button",isLoading:g,onClick:T(O),children:"Create mapping"})]})]})},Q=s.memo(J),ae=()=>{w(q.projetcMapping);const{data:o}=I(),[u,g]=s.useState(0),[d,p]=s.useState(),m=i=>({Hopsworks:n.HOPSWORKS,"LDAP/Kerberos":n.LDAP,OAuth:n.OAUTH})[i],r=s.useMemo(()=>[...o.hwGroupMappingSyncEnabled?[{title:"Hopsworks",onClick:()=>p(n.HOPSWORKS)}]:[],...o.ldapGroupMappingSyncEnabled?[{title:"LDAP/Kerberos",onClick:()=>p(n.LDAP)}]:[],...o.oauthGroupMappingSyncEnabled?[{title:"OAuth",onClick:()=>p(n.OAUTH)}]:[]],[o.hwGroupMappingSyncEnabled,o.ldapGroupMappingSyncEnabled,o.oauthGroupMappingSyncEnabled]);return s.useEffect(()=>{r[0]&&p(m(r[0].title))},[r]),e.jsxs(l,{flexGrow:1,flexDirection:"column",children:[e.jsx(S,{mb:"20px",pl:"0px",width:"150px",intent:"inline",href:E.settings.groupToProjectMapping.list,children:"<- all mappings"}),e.jsxs(K,{title:"Create new mapping",children:[e.jsx(W,{tabs:r,activeTab:u,onTabChange:g}),e.jsx(l,{mt:"20px",flexDirection:"column",children:d?e.jsx(Q,{groupType:d}):e.jsx(_,{})})]})]})};export{ae as default};
