import{r,j as e,bd as s,g as b,Q as c,A as G,z as w,bg as R,P as T,b0 as S,o as N,aY as D,fJ as E,a$ as O,E as Q,b4 as k,aU as B,b as $,aH as z,aZ as A}from"./index-ea7817a2.js";import{N as P}from"./NoData-8733f606.js";import{u as F,r as H,a as U,b as I,c as J,d as V,p as W}from"./utils-c5922439.js";import{d as Y}from"./dumbPluralize-86a9b9d6.js";const Z=({mapping:t,remoteGroups:d,isLoadingRemoteGroups:p,projectOptions:j,isLoadingProject:u,deleteCallback:x,isLoadingDelete:l})=>{const[o,n]=r.useState(!1),[a,{isLoading:h}]=F(),[m,f]=r.useState(t.remoteGroup),[g,i]=r.useState(t.projectName),[y,M]=r.useState(t.projectRole);r.useEffect(()=>{f(t.remoteGroup),i(t.projectName),M(t.projectRole)},[t.projectName,t.projectRole,t.remoteGroup]);const v=r.useCallback(async()=>{await a({id:t.id,data:{remoteGroup:m,projectName:g,projectRole:y}}),n(!1)},[t.id,g,y,m,a]),L=r.useCallback(()=>{n(!1),f(t.remoteGroup),i(t.projectName),M(t.projectRole)},[t.projectName,t.projectRole,t.remoteGroup]);return o?e.jsxs(s.Row,{children:[e.jsx(s.Cell,{children:e.jsx(b,{width:"6px",children:t.id})}),e.jsx(s.Cell,{children:e.jsx(R,{format:"fill",width:"280px",appendToBody:!0,value:m,options:d,placeholder:"pick a group",disabled:p,onChange:C=>{f(C.key)}})}),e.jsx(s.Cell,{children:e.jsx(R,{format:"fill",width:"200px",appendToBody:!0,value:g,options:j,placeholder:"pick a project",disabled:u,onChange:C=>{i(C.label)}})}),e.jsx(s.Cell,{children:e.jsx(R,{format:"fill",width:"180px",appendToBody:!0,value:y,options:H,placeholder:"pick a role",onChange:C=>{M(C.key)}})}),e.jsx(s.Cell,{pl:"0px",children:e.jsxs(c,{flexDirection:"row",children:[e.jsx(G,{intent:"ghost",icon:w.cross,tooltip:"cancel",disabled:h,onClick:L}),e.jsx(G,{intent:"ghost",icon:w.validate,tooltip:"save",disabled:h,onClick:v})]})})]}):e.jsxs(s.Row,{children:[e.jsx(s.Cell,{children:e.jsx(b,{width:"6px",children:t.id})}),e.jsx(s.Cell,{children:e.jsx(b,{width:"280px",children:t.remoteGroup})}),e.jsx(s.Cell,{children:e.jsx(b,{width:"200px",children:t.projectName})}),e.jsx(s.Cell,{children:e.jsx(b,{width:"180px",children:t.projectRole})}),e.jsx(s.Cell,{pl:"0px",children:e.jsxs(c,{flexDirection:"row",children:[e.jsx(G,{icon:w.bin,intent:"ghost",tooltip:"delete",disabled:l,onClick:()=>x(t)}),e.jsx(G,{icon:w.edit,intent:"ghost",tooltip:"edit",onClick:()=>{n(!0)}})]})})]})},q=r.memo(Z),K=({mappings:t,remoteGroups:d,isLoadingRemoteGroups:p,projectOptions:j,isLoadingProject:u})=>{const[x,l]=T(!1),[o,n]=r.useState(),[a,{isLoading:h}]=U(),m=["id","remote groups","project name","project role",""],f=r.useCallback(async()=>{o&&(await a({id:o.id}),l())},[a,l,o]),g=i=>{n(i),l()};return e.jsxs(c,{mt:"28px",mb:"28px",children:[e.jsx(S,{title:"Delete mapping",secondaryText:`Deleting this mapping will remove all members of ${o==null?void 0:o.remoteGroup} from the project ${o==null?void 0:o.projectName}`,isOpen:x,mainButtonProps:{children:"Delete",onClick:()=>f(),isLoading:h,intent:"alert"},secondaryButtonProps:{children:"Cancel",onClick:l},onClose:l}),t.length>0?e.jsx(s,{legend:m,middleColumn:3,children:t.map(i=>e.jsx(q,{mapping:i,remoteGroups:d,isLoadingRemoteGroups:p,projectOptions:j,isLoadingProject:u,deleteCallback:g,isLoadingDelete:h},i.id))}):e.jsx(N,{my:"40px",children:e.jsx(P,{fontWeight:12,mainText:"No result found"})})]})},X=r.memo(K),se=()=>{D(A.projetcMapping);const{data:t,isLoading:d}=I(),{data:p=[],isLoading:j}=J(),{data:u=[],isLoading:x}=E(),[l,o]=r.useState(""),n=r.useMemo(()=>t?t.filter(a=>a.projectName.includes(l)||a.remoteGroup.includes(l)):[],[l,t]);return d?e.jsx(O,{}):e.jsxs(Q,{title:"Remote group to project mapping",maxHeight:"calc(100vh - 215px)",contentProps:{pb:0,overflow:"auto"},children:[e.jsxs(c,{gap:"730px",children:[e.jsxs(c,{children:[e.jsx(k,{color:"primary",mr:"5px",children:(t==null?void 0:t.length)||0}),e.jsx(k,{children:Y("mapping",(t==null?void 0:t.length)||0)})]}),e.jsx(B,{href:$.settings.remoteGroupToProjectMapping.create,intent:"primary",children:"Create new mapping"})]}),t&&t.length>0?e.jsxs(e.Fragment,{children:[e.jsx(c,{mt:"10px",children:e.jsx(z,{width:"294px",value:l,icon:w.glass,placeholder:"Find by remote group or project name",onChange:({target:a})=>o(a.value)})}),e.jsx(X,{mappings:n,remoteGroups:V(p),isLoadingRemoteGroups:j,projectOptions:W(u),isLoadingProject:x})]}):e.jsx(N,{my:"40px",children:e.jsx(P,{mainText:"No remote group to project mapping found"})})]})};export{se as default};
