import{r as a,j as e}from"./vendor-react-wBh_31cN.js";import{C as N,a as A,b as O,c as G}from"./card-BeQtvmcJ.js";import{u as P}from"./useTitle-DQo_L6Ox.js";import{t as L}from"./titles-CzjGGAB3.js";import{u as k}from"./useGetAuthConfig-C2u0f3wO.js";import{P as l,G as p}from"./project-eQY1xQe-.js";import{G as C,g as F,r as H,ar as D,bh as q,as as S,bn as $,aq as w}from"./index-dNe6i2rS.js";import{o as I}from"./yup-XkUC3UEH.js";import{u as _,F as B,C as x}from"./index.esm-CAGtek53.js";import{E as M}from"./editable-select-DItn4ZHW.js";import{t as V}from"./toast-wiGcevcF.js";import{a as f}from"./getInputValidation-B3ahFDSx.js";import{c as W,H as z,O as K,L as U}from"./HWMappingForm-OAMUMOyA.js";import{u as Q}from"./index-DIs5Kizm.js";import{u as J}from"./useProjectRoleOptions-CY8oJBvb.js";import{u as X}from"./vendor-router-D1GqFWiT.js";import"./vendor-redux-CJZrIb6x.js";import"./vendor-utils-OeoE2qq_.js";import"./vendor-icons-BUUmD6ht.js";import"./vendor-radix-BRyWS4bQ.js";import"./vendor-grid-CeFlDWv4.js";import"./input-DFI7JniT.js";import"./label-gPWmc6ow.js";import"./useDebounce-BiuGz9t2.js";import"./index-odFb5xpE.js";import"./where-5NF5DPVb.js";import"./any-BVxDk2A0.js";const Y=D().shape({group:$().of(S()).min(1).label("Group").required(),projectName:S().label("Project").required(),projectRole:q().oneOf([l.DATA_OWNER,l.DATA_SCIENTIST,l.OBSERVER,l.FEATURE_STORE_RESTRICTED]).label("Role").required()}),Z=({groupType:r})=>{const d=X(),[c,{isLoading:m}]=W(),{data:u=[],isLoading:s}=Q(),i=J(),n=a.useMemo(()=>({group:[],projectName:"",projectRole:l.DATA_SCIENTIST,groupType:r}),[r]),b=_({defaultValues:n,resolver:I(Y),reValidateMode:"onSubmit"}),{register:v,handleSubmit:E,reset:h,control:g,formState:{errors:j}}=b,T=a.useCallback(async o=>{"error"in await c({data:{projectName:o.projectName,group:o.group,projectRole:o.projectRole,groupType:r}})||(h(n),V.success("Mapping created"))},[c,n,r,h]),y=()=>null,R={[p.LDAP]:U,[p.OAUTH]:K,[p.HOPSWORKS]:z}[r]||y;return e.jsxs(B,{...b,children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx(x,{name:"group",control:g,render:({field:o})=>e.jsx(R,{isEdit:!0,value:o.value?[]:o.value,onChange:t=>{o.onChange(t),v("group")},...f("group",j)})}),e.jsxs("div",{className:"flex gap-5",children:[e.jsx(x,{name:"projectName",control:g,render:({field:o})=>e.jsx(M,{isMulti:!1,preventAdding:!0,label:"Project",noResultsText:"No project found",value:o.value?[o.value]:[],options:u.map(t=>t.name)??[],placeholder:"pick a project",isLoading:s,onChange:([t])=>o.onChange(t),...f("projectName",j)})}),e.jsx(x,{name:"projectRole",control:g,render:({field:o})=>e.jsx(M,{isMulti:!1,preventAdding:!0,label:"Role",value:o.value?[o.value]:[],options:i.map(t=>t),placeholder:"pick a role",onChange:([t])=>o.onChange(t),...f("projectRole",j)})})]})]}),e.jsxs("div",{className:"mt-5 flex justify-end gap-5",children:[e.jsx(C,{type:"button",variant:"secondary",onClick:()=>d(F(H.settings.groupToProjectMapping.list)),children:"Back"}),e.jsx(C,{type:"button",loading:m,onClick:E(T),children:"Create mapping"})]})]})},ee=a.memo(Z),Ne=()=>{P(L.projetcMapping);const{data:r}=k(),[d,c]=a.useState(0),[m,u]=a.useState(),s=a.useMemo(()=>[...r.hwGroupMappingSyncEnabled?[{title:"Hopsworks",groupType:p.HOPSWORKS}]:[],...r.ldapGroupMappingSyncEnabled?[{title:"LDAP/Kerberos",groupType:p.LDAP}]:[],...r.oauthGroupMappingSyncEnabled?[{title:"OAuth",groupType:p.OAUTH}]:[]],[r.hwGroupMappingSyncEnabled,r.ldapGroupMappingSyncEnabled,r.oauthGroupMappingSyncEnabled]);return a.useEffect(()=>{s[0]&&u(s[0].groupType)},[s]),e.jsx("div",{className:"flex flex-1 flex-col",children:e.jsxs(N,{children:[e.jsx(A,{children:e.jsx(O,{children:"Create new mapping"})}),e.jsxs(G,{children:[e.jsx("div",{className:"mb-5 flex gap-0 border-b border-border",children:s.map((i,n)=>e.jsx("button",{type:"button",className:`px-4 py-2 text-xs font-bold transition-colors ${d===n?"border-b-2 border-quartz-primary text-quartz-primary":"text-quartz-gray hover:text-foreground"}`,onClick:()=>{c(n),u(i.groupType)},children:i.title},i.title))}),e.jsx("div",{className:"flex flex-col",children:m?e.jsx(ee,{groupType:m}):e.jsx(w,{})})]})]})})};export{Ne as default};
