import{r,j as e,b$ as s,b as C,B as c,e as G,C as w,bW as R,w as T,bA as D,d as k,bx as S,dw as B,L as O,y as E,bG as N,bq as $,b4 as Q,s as F,b5 as I,by as W}from"./index-C1DmWO_C.js";import{N as v}from"./NoData-Y_e6mfNf.js";import{u as q,r as z,a as A,b as H,c as J,d as U,p as K}from"./utils-JD3SOAYH.js";const V=({mapping:t,remoteGroups:d,isLoadingRemoteGroups:p,projectOptions:j,isLoadingProject:u,deleteCallback:x,isLoadingDelete:l})=>{const[o,a]=r.useState(!1),[i,{isLoading:h}]=q(),[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(C,{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:g=>{b(g.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:g=>{n(g.label)}})}),e.jsx(s.Cell,{children:e.jsx(R,{format:"fill",width:"180px",appendToBody:!0,value:y,options:z,placeholder:"pick a role",onChange:g=>{M(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: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(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:()=>{a(!0)}})]})})]})},X=r.memo(V),Y=({mappings:t,remoteGroups:d,isLoadingRemoteGroups:p,projectOptions:j,isLoadingProject:u})=>{const[x,l]=T(!1),[o,a]=r.useState(),[i,{isLoading:h}]=A(),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(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:()=>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(X,{mapping:n,remoteGroups:d,isLoadingRemoteGroups:p,projectOptions:j,isLoadingProject:u,deleteCallback:f,isLoadingDelete:h},n.id))}):e.jsx(k,{my:"40px",children:e.jsx(v,{fontWeight:12,mainText:"No result found"})})]})},Z=r.memo(Y),oe=()=>{S(W.projetcMapping);const{data:t,isLoading:d}=H(),{data:p=[],isLoading:j}=J(),{data:u=[],isLoading:x}=B(),[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(O,{}):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(N,{color:"primary",mr:"5px",children:(t==null?void 0:t.length)||0}),e.jsx(N,{children:$("mapping",(t==null?void 0:t.length)||0)})]}),e.jsx(Q,{href:F.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(Z,{mappings:a,remoteGroups:U(p),isLoadingRemoteGroups:j,projectOptions:K(u),isLoadingProject:x})]}):e.jsx(k,{my:"40px",children:e.jsx(v,{mainText:"No remote group to project mapping found"})})]})};export{oe as default};
