import{r,j as e,bw as s,p as C,d as c,e as G,T as w,bs as M,w as P,be as D,c as N,bb as S,cZ as O,L as E,Q as B,aV as k,b6 as Q,q as $,aR as F,bc as V}from"./index-CK33qGU_.js";import{N as v}from"./NoData-CuLyR2Bg.js";import{u as q,r as z,a as H,b as I,c as J,d as U,p as W}from"./utils-B1ZrsCe9.js";import{d as Z}from"./dumbPluralize-CcxDsNiu.js";const A=({mapping:t,remoteGroups:d,isLoadingRemoteGroups:p,projectOptions:j,isLoadingProject:u,deleteCallback:x,isLoadingDelete:l})=>{const[o,n]=r.useState(!1),[i,{isLoading:h}]=q(),[m,f]=r.useState(t.remoteGroup),[b,a]=r.useState(t.projectName),[y,R]=r.useState(t.projectRole);r.useEffect(()=>{f(t.remoteGroup),a(t.projectName),R(t.projectRole)},[t.projectName,t.projectRole,t.remoteGroup]);const T=r.useCallback(async()=>{await i({id:t.id,data:{remoteGroup:m,projectName:b,projectRole:y}}),n(!1)},[t.id,b,y,m,i]),L=r.useCallback(()=>{n(!1),f(t.remoteGroup),a(t.projectName),R(t.projectRole)},[t.projectName,t.projectRole,t.remoteGroup]);return o?e.jsxs(s.Row,{children:[e.jsx(s.Cell,{children:e.jsx(C,{width:"6px",children:t.id})}),e.jsx(s.Cell,{children:e.jsx(M,{format:"fill",width:"280px",appendToBody:!0,value:m,options:d,placeholder:"pick a group",disabled:p,onChange:g=>{f(g.key)}})}),e.jsx(s.Cell,{children:e.jsx(M,{format:"fill",width:"200px",appendToBody:!0,value:b,options:j,placeholder:"pick a project",disabled:u,onChange:g=>{a(g.label)}})}),e.jsx(s.Cell,{children:e.jsx(M,{format:"fill",width:"180px",appendToBody:!0,value:y,options:z,placeholder:"pick a role",onChange:g=>{R(g.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:T})]})})]}):e.jsxs(s.Row,{children:[e.jsx(s.Cell,{children:e.jsx(C,{width:"6px",children:t.id})}),e.jsx(s.Cell,{children:e.jsx(C,{width:"280px",children:t.remoteGroup})}),e.jsx(s.Cell,{children:e.jsx(C,{width:"200px",children:t.projectName})}),e.jsx(s.Cell,{children:e.jsx(C,{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)}})]})})]})},K=r.memo(A),X=({mappings:t,remoteGroups:d,isLoadingRemoteGroups:p,projectOptions:j,isLoadingProject:u})=>{const[x,l]=P(!1),[o,n]=r.useState(),[i,{isLoading:h}]=H(),m=["id","remote groups","project name","project role",""],f=r.useCallback(async()=>{o&&(await i({id:o.id}),l())},[i,l,o]),b=a=>{n(a),l()};return e.jsxs(c,{mt:"28px",mb:"28px",children:[e.jsx(D,{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(a=>e.jsx(K,{mapping:a,remoteGroups:d,isLoadingRemoteGroups:p,projectOptions:j,isLoadingProject:u,deleteCallback:b,isLoadingDelete:h},a.id))}):e.jsx(N,{my:"40px",children:e.jsx(v,{fontWeight:12,mainText:"No result found"})})]})},Y=r.memo(X),se=()=>{S(V.projetcMapping);const{data:t,isLoading:d}=I(),{data:p=[],isLoading:j}=J(),{data:u=[],isLoading:x}=O(),[l,o]=r.useState(""),n=r.useMemo(()=>t?t.filter(i=>i.projectName.includes(l)||i.remoteGroup.includes(l)):[],[l,t]);return d?e.jsx(E,{}):e.jsxs(B,{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:Z("mapping",(t==null?void 0:t.length)||0)})]}),e.jsx(Q,{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(F,{width:"294px",value:l,icon:w.glass,placeholder:"Find by remote group or project name",onChange:({target:i})=>o(i.value)})}),e.jsx(Y,{mappings:n,remoteGroups:U(p),isLoadingRemoteGroups:j,projectOptions:W(u),isLoadingProject:x})]}):e.jsx(N,{my:"40px",children:e.jsx(v,{mainText:"No remote group to project mapping found"})})]})};export{se as default};
