import{p as v,q as g,s as f,r as l,u as E,a_ as Q,j as t,b0 as V,af as A,bQ as P,cu as L,Q as h,b4 as j,x as O,bq as z,o as U,a3 as $,a4 as I,aU as T,cj as D}from"./index-ea7817a2.js";import{d as F}from"./dumbPluralize-86a9b9d6.js";const G=v.injectEndpoints({endpoints:e=>({getMembers:e.query({query:({id:c})=>({url:`project/${c}/projectMembers`})}),addMembers:e.mutation({query:({id:c,data:o})=>({url:`project/${c}/projectMembers`,method:"post",data:o}),invalidatesTags:g.cacheByIdArgProperty(f.ProjectTags.Project)}),deleteMember:e.mutation({query:({id:c,email:o})=>({url:`project/${c}/projectMembers/${o}`,method:"delete"}),invalidatesTags:g.cacheByIdArgProperty(f.ProjectTags.Project)}),editMemberRole:e.mutation({query:({id:c,email:o,role:d})=>({url:`project/${c}/projectMembers/${o}`,method:"post",data:new URLSearchParams({role:d}).toString()}),invalidatesTags:g.cacheByIdArgProperty(f.ProjectTags.Project)})})}),{useGetMembersQuery:X,useAddMembersMutation:J,useDeleteMemberMutation:Y,useEditMemberRoleMutation:Z}=G;var S=(e=>(e.DataScientist="Data scientist",e.DataOwner="Data owner",e))(S||{});const N=({members:e,isOpen:c,isSearchEnabled:o,onClose:d})=>{const{id:u}=E(),m=Q(),[M]=J(),[p,C]=l.useState([]),[i,R]=l.useState([]),[x,w]=l.useState([]),[y,b]=l.useState(!1);l.useEffect(()=>{const a=i.map((r,s)=>({projectTeamPK:{projectId:+u,teamMember:r},teamRole:x[s]}));C(a)},[i,x,e,u]);const k=a=>{const r=i.filter(n=>!a.includes(n)).map(n=>i.indexOf(n)),s=a.filter(n=>!i.includes(n));R(a),w(n=>[...n.filter((W,B)=>!r.includes(B)),...s.map(()=>"Data owner")])},_=(a,r)=>{w(s=>[...s.slice(0,r),...a,...s.slice(r+1)])},q=l.useCallback(async()=>{b(!0);try{await M({id:+u,data:{projectTeam:p}}).unwrap();const a=p.map(({projectTeamPK:r})=>{const s=e.find(n=>n.email===r.teamMember);return e.length?s==null?void 0:s.firstname:r.teamMember}).join(", ");m.success({title:`${p.length} ${F("member",p.length)} added`,content:`${a} has been added to the project`})}catch{}finally{b(!1)}d()},[d,M,u,p,m,e]);return t.jsxs(V,{size:"sm",title:"Add members",isOpen:c,onClose:d,mainButtonProps:{children:"Add members",onClick:q,disabled:!(e!=null&&e.length)&&o||!p.length,isLoading:y},secondaryButtonProps:{children:"Back",onClick:d},children:[o?t.jsx(A,{mainText:"All members of this cluster are part of this project",disabled:!!(e!=null&&e.length),children:t.jsx(P,{isMulti:!0,preventAdding:!0,value:i,label:"Members",placeholder:"pick members",noDataMessage:"no members defined",onChange:k,disabled:!(e!=null&&e.length)||y,options:e==null?void 0:e.map(({email:a})=>a)})}):t.jsx(A,{mainText:"Enter the email of a user you want to add",children:t.jsx(P,{width:"100%",isMulti:!0,label:"Members",value:i,placeholder:"enter an email",options:[],onChange:k})}),i.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(L,{px:"20px"}),i.map((a,r)=>{const s=e.find(n=>n.email===a);return t.jsxs(h,{flexDirection:"row",mb:"20px",justifyContent:"space-between",children:[t.jsxs(h,{flexDirection:"column",children:[o&&t.jsx(j,{mb:"5px",children:`${s==null?void 0:s.firstname} ${s==null?void 0:s.lastname}`}),t.jsx(O,{sx:{wordBreak:"break-all",marginRight:"10px"},children:a})]}),t.jsx(z,{mb:"5px",value:[x[r]],placeholder:"",listWidth:"100%",onChange:n=>_(n,r),options:Object.values(S)})]},a)})]}),t.jsx(U,{my:"20px",children:e!=null&&e.length||!o?t.jsx($,{type:I.neutral,content:t.jsxs(h,{alignItems:"center",children:[t.jsx(j,{children:"In order to add a new user, follow the steps"}),t.jsx(T,{pl:"3px",onClick:()=>window.open("https://docs.hopsworks.ai/".concat(D.docsVersion,"/user_guides/projects/project/add_members/"),"_blank"),intent:"inline",children:"here↗"})]})}):t.jsx($,{type:I.warning,content:t.jsxs(h,{flexDirection:"column",alignItems:"center",children:[t.jsx(j,{sx:{whiteSpace:"break-spaces"},children:"All members of this cluster are part of this project. In order to"}),t.jsxs(h,{width:"100%",children:[t.jsx(j,{children:"add a new user, follow the steps here"}),t.jsx(T,{pl:"3px",my:"-8px",onClick:()=>window.open("https://docs.hopsworks.ai/".concat(D.docsVersion,"/user_guides/projects/project/add_members/"),"_blank"),intent:"inline",children:"here↗"})]})]})})})]})},ee=l.memo(N);export{ee as A,S as R,Y as a,Z as b,J as u};
