import{t as e}from"./charges-table-CIL9Y7el.js";import{Eu as t,Lt as n,Nl as r,Pd as i,Xu as a,Zu as o,ed as s,ql as c,tn as l,tr as u,ya as d,zd as f}from"./index-Q5R6-AeA.js";import{t as p}from"./use-url-query-Cos8nKH-.js";import{t as m}from"./page-layout-Cl29SycZ.js";import{t as h}from"./charges-filters-CY1Akgqt.js";var g=f(i(),1),_=t(),v=()=>{let{setFiltersContext:t}=(0,g.useContext)(u),[i,f]=(0,g.useState)(!1),[v,y]=(0,g.useState)([]),{get:b}=p(),[x,S]=(0,g.useState)(b(`page`)?Number(b(`page`)):0),C=b(`chargesFilters`),w=(0,g.useMemo)(()=>{if(C)try{return JSON.parse(decodeURIComponent(C))}catch{return}},[C]),[T,E]=(0,g.useState)(w),D=(0,g.useCallback)((e,t)=>{v.map(e=>e.id).includes(e)?y(v.filter(t=>t.id!==e)):y([...v,{id:e,onChange:t}])},[v]),[{data:O,fetching:k},A]=r({query:d,variables:{filters:T,page:x,limit:100},pause:!0});(0,g.useEffect)(()=>{T&&A()},[T,A]);function j(){y([])}return(0,g.useEffect)(()=>{t((0,_.jsxs)(`div`,{className:`flex flex-row gap-x-5`,children:[(0,_.jsx)(h,{filter:T,setFilter:E,activePage:x,setPage:S,totalPages:O?.allCharges?.pageInfo.totalPages,initiallyOpened:!T}),(0,_.jsx)(l,{content:`Expand all accounts`,children:(0,_.jsx)(c,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:()=>f(e=>!e),children:i?(0,_.jsx)(o,{className:`size-5`}):(0,_.jsx)(a,{className:`size-5`})})}),(0,_.jsx)(n,{selected:v,resetMerge:j})]}))},[O,k,T,x,i,t,S,E,f,v,w]),(0,_.jsx)(m,{title:`All Charges`,description:`Manage charges`,children:k?(0,_.jsx)(s,{className:`h-10 w-10 animate-spin mr-2 self-center`}):O?.allCharges.nodes?(0,_.jsx)(e,{toggleMergeCharge:D,mergeSelectedCharges:new Set(v.map(e=>e.id)),data:O?.allCharges?.nodes,isAllOpened:i}):(0,_.jsx)(`span`,{children:`Please apply filters`})})};export{v as AllCharges};