import{r,j as e,b_ as s,f as g,$ as c,i as G,C as w,bV as R,y as D,bz as T,L as N,bS as v,bw as S,bx as O,dP as $,D as B,b as E,bF as k,bp as F,b1 as Q,q as z,b2 as I}from"./index-46ma1THH.js";import{u as _,r as q,a as H,b as J,c as U,p as V,d as W}from"./utils-DMrJxpVL.js";const A=({mapping:t,remoteGroups:d,isLoadingRemoteGroups:p,projectOptions:j,isLoadingProject:u,deleteCallback:x,isLoadingDelete:l})=>{const[o,a]=r.useState(!1),[i,{isLoading:h}]=_(),[m,b]=r.useState(t.remoteGroup),[f,n]=r.useState(t.projectName),[y,M]=r.useState(t.projectRole);r.useEffect(()=>{b(t.remoteGroup),n(t.projectName),M(t.projectRole)},[t.projectName,t.projectRole,t.remoteGroup]);const L=r.useCallback(async()=>{await i({id:t.id,data:{remoteGroup:m,projectName:f,projectRole:y}}),a(!1)},[t.id,f,y,m,i]),P=r.useCallback(()=>{a(!1),b(t.remoteGroup),n(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(g,{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=>{b(C.key)}})}),e.jsx(s.Cell,{children:e.jsx(R,{format:"fill",width:"200px",appendToBody:!0,value:f,options:j,placeholder:"pick a project",disabled:u,onChange:C=>{n(C.label)}})}),e.jsx(s.Cell,{children:e.jsx(R,{format:"fill",width:"180px",appendToBody:!0,value:y,options:q,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:P}),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(g,{width:"6px",children:t.id})}),e.jsx(s.Cell,{children:e.jsx(g,{width:"280px",children:t.remoteGroup})}),e.jsx(s.Cell,{children:e.jsx(g,{width:"200px",children:t.projectName})}),e.jsx(s.Cell,{children:e.jsx(g,{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:()=>{a(!0)}})]})})]})},K=r.memo(A),X=({mappings:t,remoteGroups:d,isLoadingRemoteGroups:p,projectOptions:j,isLoadingProject:u})=>{const[x,l]=D(!1),[o,a]=r.useState(),[i,{isLoading:h}]=H(),m=["id","remote groups","project name","project role",""],b=r.useCallback(async()=>{o&&(await i({id:o.id}),l())},[i,l,o]),f=n=>{a(n),l()};return e.jsxs(c,{mt:"28px",mb:"28px",children:[e.jsx(T,{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:()=>b(),isLoading:h,intent:"alert"},secondaryButtonProps:{children:"Cancel",onClick:l},onClose:l}),t.length>0?e.jsx(s,{legend:m,middleColumn:3,children:t.map(n=>e.jsx(K,{mapping:n,remoteGroups:d,isLoadingRemoteGroups:p,projectOptions:j,isLoadingProject:u,deleteCallback:f,isLoadingDelete:h},n.id))}):e.jsx(N,{my:"40px",children:e.jsx(v,{fontWeight:12,mainText:"No result found"})})]})},Y=r.memo(X),te=()=>{S(O.projetcMapping);const{data:t,isLoading:d}=J(),{data:p=[],isLoading:j}=U(),{data:u=[],isLoading:x}=$(),[l,o]=r.useState(""),a=r.useMemo(()=>t?t.filter(i=>i.projectName.includes(l)||i.remoteGroup.includes(l)):[],[l,t]);return d?e.jsx(B,{}):e.jsxs(E,{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:F("mapping",(t==null?void 0:t.length)||0)})]}),e.jsx(Q,{href:z.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(I,{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:a,remoteGroups:W(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{te as default};
