import{r,j as e,bX as s,Q as b,B as c,f as G,Z as w,bT as R,c as P,bE as D,e as N,bC as S,dp as B,L as E,m as O,bK as k,aG as Q,s as $,aM as F,bD as Z}from"./index-dP1W1_bd.js";import{N as v}from"./NoData-DLZ_8GEo.js";import{u as _,r as z,a as H,b as I,c as K,d as U,p as V}from"./utils-BPA-fYzf.js";import{d as W}from"./dumbPluralize-CcxDsNiu.js";const X=({mapping:t,remoteGroups:d,isLoadingRemoteGroups:p,projectOptions:j,isLoadingProject:u,deleteCallback:x,isLoadingDelete:l})=>{const[o,n]=r.useState(!1),[i,{isLoading:h}]=_(),[m,f]=r.useState(t.remoteGroup),[g,a]=r.useState(t.projectName),[M,y]=r.useState(t.projectRole);r.useEffect(()=>{f(t.remoteGroup),a(t.projectName),y(t.projectRole)},[t.projectName,t.projectRole,t.remoteGroup]);const L=r.useCallback(async()=>{await i({id:t.id,data:{remoteGroup:m,projectName:g,projectRole:M}}),n(!1)},[t.id,g,M,m,i]),T=r.useCallback(()=>{n(!1),f(t.remoteGroup),a(t.projectName),y(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=>{a(C.label)}})}),e.jsx(s.Cell,{children:e.jsx(R,{format:"fill",width:"180px",appendToBody:!0,value:M,options:z,placeholder:"pick a role",onChange:C=>{y(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:T}),e.jsx(G,{intent:"ghost",icon:w.validate,tooltip:"save",disabled:h,onClick:L})]})})]}):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(X),A=({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]),g=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(q,{mapping:a,remoteGroups:d,isLoadingRemoteGroups:p,projectOptions:j,isLoadingProject:u,deleteCallback:g,isLoadingDelete:h},a.id))}):e.jsx(N,{my:"40px",children:e.jsx(v,{fontWeight:12,mainText:"No result found"})})]})},J=r.memo(A),se=()=>{S(Z.projetcMapping);const{data:t,isLoading:d}=I(),{data:p=[],isLoading:j}=K(),{data:u=[],isLoading:x}=B(),[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(O,{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:W("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(J,{mappings:n,remoteGroups:U(p),isLoadingRemoteGroups:j,projectOptions:V(u),isLoadingProject:x})]}):e.jsx(N,{my:"40px",children:e.jsx(v,{mainText:"No remote group to project mapping found"})})]})};export{se as default};
