import{r,j as e,bc as s,f as b,a as c,V as G,Z as w,bf as R,l as D,a$ as P,O as N,aX as S,fD as O,a_ as B,K as E,b3 as k,aT as $,e as Q,aG as U,aY as F}from"./index-d6499a22.js";import{N as v}from"./NoData-789df290.js";import{u as K,r as V,a as Z,b as z,c as H,d as I,p as W}from"./utils-b8e6cf24.js";import{d as X}from"./dumbPluralize-86a9b9d6.js";const Y=({mapping:t,remoteGroups:d,isLoadingRemoteGroups:p,projectOptions:j,isLoadingProject:u,deleteCallback:x,isLoadingDelete:l})=>{const[o,n]=r.useState(!1),[a,{isLoading:h}]=K(),[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 L=r.useCallback(async()=>{await a({id:t.id,data:{remoteGroup:m,projectName:g,projectRole:y}}),n(!1)},[t.id,g,y,m,a]),T=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:V,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: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)}})]})})]})},_=r.memo(Y),q=({mappings:t,remoteGroups:d,isLoadingRemoteGroups:p,projectOptions:j,isLoadingProject:u})=>{const[x,l]=D(!1),[o,n]=r.useState(),[a,{isLoading:h}]=Z(),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(P,{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(_,{mapping:i,remoteGroups:d,isLoadingRemoteGroups:p,projectOptions:j,isLoadingProject:u,deleteCallback:g,isLoadingDelete:h},i.id))}):e.jsx(N,{my:"40px",children:e.jsx(v,{fontWeight:12,mainText:"No result found"})})]})},A=r.memo(q),se=()=>{S(F.projetcMapping);const{data:t,isLoading:d}=z(),{data:p=[],isLoading:j}=H(),{data:u=[],isLoading:x}=O(),[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(B,{}):e.jsxs(E,{title:"Remote group to project mapping",maxHeight:"calc(100vh - 230px)",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:X("mapping",(t==null?void 0:t.length)||0)})]}),e.jsx($,{href:Q.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(U,{width:"294px",value:l,icon:w.glass,placeholder:"Find by remote group or project name",onChange:({target:a})=>o(a.value)})}),e.jsx(A,{mappings:n,remoteGroups:I(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};
