1import{j as e,N as _,e3 as ce,i as q,d as re,r as k,e4 as H,e5 as U,b as ie,s as de,e2 as ue,e6 as P,e7 as le,a4 as E,L as W,e8 as me,e9 as pe}from"./index-Durs5I49.js";import{a as i,d as ge}from"./vendor-core-C0v-OB8t.js";import{T as he,V as fe}from"./ViewManagementItems-BltZtSka.js";import{D as F,V as ye}from"./ViewManagementItemTitle-BzxjXIKA.js";import{T as K}from"./TeamManagementGrid-KFYctY8l.js";import{S as Ae}from"./remove-new-DcZ13HUf.js";import{Q as R,ak as xe,aq as Me}from"./App-BRqth97V.js";import{M as z,A as Se}from"./MoreButtonPopup-TK_TZtI4.js";import{s as Q}from"./modals.module-Cqd5_m9X.js";import{u as be,a as je}from"./useHandleIdQueryParams-B6395TQX.js";import{u as De}from"./useFetchData-DkrAYDWs.js";import{u as ve,R as Ie}from"./RenameModal-DqTj3q7V.js";import{u as we}from"./useGetTeamManagementData-D8bncNb8.js";import{F as Ce,y as Te,w as ke}from"./vendor-ant-ui-DJ2XyNgH.js";import"./BlockContent-9qh1FceN.js";import"./UserFullNameWithIcon-DYKD2ebu.js";import"./TooltipWrapper-Bnej9WWb.js";import"./AppDataGridCheckboxFormatter-DeSYufOl.js";import"./DataGridWrapper-D2ne16oR.js";import"./bundle-BH_tP1Fa.js";import"./BlockHeader-CnDQoG2O.js";import"./useDebounce-DPZL502a.js";import"./useDebouncedCallback-BA5LXvRQ.js";import"./Filter-B3Y6ar6X.js";import"./FilterBlock-rrwwGc05.js";import"./FilterButton-DitB6crd.js";import"./FilterCounter-DHpXXQvc.js";import"./filter-reset-fuWTjxWT.js";import"./SelectedItem-HxcF0wuC.js";import"./CustomSelectOption-Ce7YQUnx.js";import"./ArrowToggleSmall-B010zd9O.js";import"./gear-BynBejKH.js";import"./ResourcesFooterPanel-BQqW7obK.js";import"./ResourcesNotFound-DsZLgCoR.js";import"./usePrevious-C2OZYJc_.js";import"./Radio-IBpD7yaZ.js";import"./useMultiQuickFiltersResponsive-MKJ4wwy2.js";import"./useWindowSize-CqXTfVK3.js";import"./SuspendWrapper-Br-qnoPf.js";import"./SuspendGrid-BKk4wxNf.js";import"./SwitchSelectWithIcons-D96FTiLn.js";import"./SwitchSelect.module-BauwmYHM.js";import"./Table-pg3Toxuv.js";
1import"./functions-helper-B9VZvDZU.js";import"./main-C5bqmb-M.js";import"./main-BAS4d6YV.js";import"./ColumnsPlusRight.es-DndRVqgl.js";import"./objectWithoutPropertiesLoose-GaTtslse.js";import"./FlexLite-BSoUgFt_.js";const Ne="accounts_OWFT1",Ee={accounts:Ne},Re="editManagementItems_Fnw-o",_e="header_ZMP4W",Fe="name_stiA3",Ge="table_8GRFt",Oe="badge_Kjks-",T={editManagementItems:Re,header:_e,name:Fe,table:Ge,badge:Oe},Le=({name:u,btn:s,data:h,viewType:S,selectedItem:y,disabledIds:c,deleteModalProps:f,onDelete:I,getMoreData:A})=>{const[t,m]=i.useState([]),[b,x]=i.useState(!1);return i.useEffect(()=>{m([])},[S,y]),e.jsxs("div",{className:T.editManagementItems,children:[e.jsxs("div",{className:T.header,children:[e.jsx("div",{className:T.name,children:u}),e.jsx(_,{size:"small",text:s.text,disabled:s.disabled,type:"transparent",renderLeft:()=>e.jsx("span",{children:"+"}),onClick:()=>s.onClick()})]}),e.jsxs("div",{className:T.table,children:[e.jsx(K,{checkedResourceIds:t,data:h,name:u,setCheckedResourceIds:m,viewType:S,disabledIds:c,gridType:"editItemsBlock",minRowsCountToShow:2,getMoreData:A?j=>A(j).map(M=>M.label===ce?{...M,onClick(){m([String(j)]),x(!0)}}:M):void 0}),!!t.length&&e.jsxs("div",{className:T.badge,children:[e.jsxs("div",{children:[t.length," item selected"]}),e.jsx(_,{size:"small",text:`Remove ${u}`,type:"transparent-red",onClick:()=>x(!0),renderLeft:()=>e.jsx(Ae,{width:16,height:16})})]})]}),b&&e.jsx(F,{...f,onDelete:async()=>{await I({checkedIds:t,data:h})},onClose:()=>x(!1)})]})},Ve=({filterByAccounts:u,selectedItemData:s,viewType:h,data:S,disabledIds:y,onClose:c})=>{const f=ge(),I=q(),{id:A}=re(),t=i.useMemo(()=>{if(s){if("accounts"in s)return s.accounts.map(p=>p+"");if("groups"in s)return s.groups.map(p=>p+"")}return[]},[s]),[m,b]=i.useState(t),[x,j]=i.useState(!1),M=async()=>{s&&(j(!0),h.type==="accounts"?await I(H({data:{accounts:m.map(p=>+p)},groupId:s==null?void 0:s.id,orgId:A})):await I(U({data:{groups:m.map(p=>+p)},accountId:s.id,orgId:A})),c(),j(!1))};return e.jsxs(R,{style:{width:578},onClose:c,children:[e.jsx(R.Title,{children:u?"Add an Account to a Set of Accounts":"Add Account to the Set"}),!u&&e.jsxs(R.SupTitle,{children:["Select the accounts you want to group, ",e.jsx("br",{})," or"," ",e.jsx("span",{className:Q.link,onClick:()=>f(k.accountManagerAdd),children:"connect"})," ","a new account to display it in the list"]}),e.jsx(R.Content,{children:e.jsx(K,{checkedResourceIds:m,data:S,name:"name",setCheckedResourceIds:b,viewType:h,disabledIds:y,gridType:"modal"})}),e.jsxs("div",{className:Q.buttons,children:[e.jsx(_,{size:"medium",text:"Cancel",type:"transparent",onClick:c,disabled:x}),e.jsx(_,{size:"medium",text:"Save",type:"blue",onClick:M,submitting:x})]})]})},Gt=()=>{const{accountsGroup:u,cloudAccounts:s}=we();De();const h=q(),{filterValue:S,setFilterValue:y,selectedItem:c,setSelectedItem:f,deleteModalOpen:I,setDeleteModalOpen:A,filterByAccounts:t,navigate:m,orgId:b}=be(),{isDisconnectModalOpened:x,onDisconnect:j,setIsDisconnectModalOpened:M}=ve(),p=ie(a=>a.aws.entities.environments,de),G=i.useMemo(()=>ue(p),[p]),[O,L]=i.useState(null),[Y,V]=i.useState(null),D=i.useMemo(()=>P(s.data||[]),[s.data]),v=i.useMemo(()=>P(u.data||[]),[u.data]),[Z,B]=i.useState(!1),g=i.useMemo(()=>{var a,d;return c?t?((a=s.data)==null?void 0:a[c])||null:((d=u.data)==null?void 0:d[c])||null:null},[c,t,s.data,u.data]),{disabledIds:N,isSelectedItemSystem:J}=i.useMemo(()=>{var n,o;const a=c&&!t?(o=(n=u.data)==null?void 0:n[c])==null?void 0:o.system:!1,d=t?le(v):a?D.map(r=>String(r.id)):void 0;return{isSelectedItemSystem:a,disabledIds:d}},[c,t,u.data,v,D]);i.useEffect(()=>{var n,o;const a=t?s:u,d=t?D:v;(!c||!((n=a.data)!=null&&n[c]))&&d.length&&f((o=d[0])==null?void 0:o.id)},[v,D,t,c]);const X=i.useCallback(a=>(y("accounts"),s.data&&s.data[a]?(f(a),!0):!1),[s.data]),ee=i.useMemo(()=>(t?D:v).map(d=>{if(t){const{id:n,name:o,groups:r,provider:l,cloud_id:C}=d;return{id:n,description:`${r.length} Account Sets`,name:{renderName:()=>e.jsx(Se,{accountName:o,provider:l,account_id:C}),nameStrValue:o},moreButton:e.jsx(z,{data:[{disabled:!1,label:"View",onClick:()=>{const $=G[C];$!=null&&m(k.accountManager,{state:{detailsEnvId:$}})}},{label:"Rename",disabled:!1,onClick:()=>L(d)},{disabled:!1,label:"Disconnect",onClick:()=>{M(!0)}}]},n),searchData:`${o} ${C}`,sortData:{name:o,groups:r.length}}}else{const{id:n,accounts:o,name:r,system:l}=d;return{id:n,description:`${o.length} Accounts `,name:{nameStrValue:r+(l?" (system)":""),renderName(){return e.jsx(ye,{name:r,system:l})}},moreButton:!l&&e.jsx(z,{data:[{label:"Edit",disabled:!1,onClick:()=>m(k.teamManagementAccountsEdit+"/"+n)},{label:"Remove",disabled:!1,onClick:()=>{f(n),A(!0)}}]},n),sortData:{name:r,accounts:o.length,system:l}}}})||[],[v,D,S,G]),te=i.useMemo(()=>{const a={ASC:1,DESC:-1},d=(o,r,l,C)=>o.sortData.system!==void 0&&r.sortData.system!==void 0&&o.sortData.system!==r.sortData.system?E({a:o.sortData.system,b:r.sortData.system})*a[l]:C,n=[{key:"name",sortFn:(o,r,l)=>
1d(o,r,l,E({a:o.sortData.name,b:r.sortData.name})),sortName:"Name"}];return t?n.push({key:"groups",sortFn:(o,r,l)=>d(o,r,l,E({a:o.sortData.groups,b:r.sortData.groups})),sortName:"Account Sets"}):n.push({key:"accounts",sortFn:(o,r,l)=>d(o,r,l,E({a:o.sortData.accounts,b:r.sortData.accounts})),sortName:"Accounts"}),n},[t]),ae=s.loadingState===W.isLoaded&&u.loadingState===W.isLoaded,w=i.useMemo(()=>t?{type:"accountsGroup",data:u.data||{}}:{type:"accounts",data:s.data||{}},[t,u,s]),se=i.useMemo(()=>g?t?g.groups:g.accounts:[],[g,t]),oe=i.useMemo(()=>({title:t?"Remove Accounts Set?":"Remove Accounts?",description:t?"Are you sure you want to remove accounts set? The accounts in this set will not be deleted and can be added to a new set later.":"Are you sure you want to remove accounts from this account set? The accounts in this set will not be deleted and can be added to a new set later."}),[t]),{id:ne}=je({queryParam:Me.account_id,selectItem:X});return ae?e.jsxs("div",{className:Ee.accounts,children:[e.jsxs(Ce,{align:"center",gap:10,style:{padding:"0 16px"},children:[e.jsx(Te.Text,{children:"View by"}),e.jsx(ke,{options:[{label:"Accounts",value:"accounts"},{label:"Account Set",value:"account-set"}],styles:{root:{width:130}},value:S,onChange:a=>y(a),"data-testid":"view-by-selector"})]}),e.jsxs(he,{children:[e.jsx(fe,{btn:{text:t?"Add new account":"Add new set",onClick:()=>m(t?k.accountManagerAdd:k.teamManagementAccountsNewSet)},selectedItem:c,setSelectedItem:f,name:t?"Accounts":"Account Sets",data:ee,sortData:te,scrollToId:Y??ne,setIdFromQuery:a=>V(a)}),e.jsx(Le,{btn:{text:t?"Add Set":"Add Account",onClick:()=>B(!0),disabled:J},name:t?"Accounts Set":"Account",data:se,viewType:w,selectedItem:c,disabledIds:N,onDelete:async({checkedIds:a,data:d})=>{if(c){const n=d.filter(o=>!a.includes(o+""));w.type==="accounts"&&await h(H({data:{accounts:n},groupId:c,orgId:b})),w.type==="accountsGroup"&&await h(U({data:{groups:n},accountId:c,orgId:b}))}},deleteModalProps:oe,getMoreData:me({moveTo:a=>{w.type==="accounts"&&y("accounts"),w.type==="accountsGroup"&&y("account-set"),f(a),V(a)},isRemoveDisabled:a=>N?N.includes(String(a)):!1})})]}),Z&&e.jsx(Ve,{data:(t?v:D).map(a=>a.id),viewType:w,filterByAccounts:t,onClose:()=>B(!1),selectedItemData:g,disabledIds:N}),I&&g&&e.jsx(F,{title:"Remove Account Set?",description:e.jsxs(e.Fragment,{children:["Are you sure you want to delete this account set?",e.jsx("br",{}),"The accounts in this set will not be deleted and can be added to a new set later. However, this action ",e.jsx("br",{})," cannot be undone."]}),onDelete:async()=>{await h(pe({groupId:g.id,orgId:b}))},onClose:()=>A(!1)}),x&&g&&e.jsx(F,{title:"Disconect account?",description:"Are you sure you want to disconect this account? However, this action cannot be undone.",deleteButtonText:"Disconnect",onDelete:async()=>{var d,n;const a=(n=(d=s.data)==null?void 0:d[g.id])==null?void 0:n.cloud_id;a&&await j({teamManagementCloudAccountId:g.id,account_id:a})},onClose:()=>M(!1)}),O&&e.jsx(Ie,{account:O,onClose:()=>L(null)})]}):e.jsx(xe,{})};export{Gt as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.