import{s as e,t}from"./charges-table-CIL9Y7el.js";import{t as n}from"./Progress-H9AtEFHT.js";import{Au as r,Eu as i,Io as a,Lt as o,Nl as s,Pd as c,Rd as l,Wr as u,Xu as d,Zu as f,ed as p,ju as m,ql as h,tn as g,tr as _,vd as v,zd as y}from"./index-Q5R6-AeA.js";import{t as b}from"./use-url-query-Cos8nKH-.js";import{t as x}from"./page-layout-Cl29SycZ.js";import{t as S}from"./charges-filters-CY1Akgqt.js";var C=l({ChargesLedgerValidation:()=>D,getLedgerValidationHref:()=>E}),w=y(c(),1),T=i();function E(e,t){let n=new URLSearchParams;t&&n.append(`page`,String(t));let i=m(e);i&&n.append(`chargesFilters`,i);let a=n.size>0?`?${n}`:``;return`${r.CHARGES.LEDGER_VALIDATION}${a}`}var D=()=>{let{setFiltersContext:r}=(0,w.useContext)(_),[i,c]=(0,w.useState)(!1),[l,m]=(0,w.useState)([]),{get:y}=b(),C=y(`chargesFilters`),[E,D]=(0,w.useState)((0,w.useMemo)(()=>{if(C)try{return JSON.parse(decodeURIComponent(C))}catch{return}},[C])),O=(0,w.useCallback)((e,t)=>{l.map(e=>e.id).includes(e)?m(l.filter(t=>t.id!==e)):m([...l,{id:e,onChange:t}])},[l]),[{data:k,fetching:A},j]=s({query:a,variables:{filters:E},pause:!0});function M(){m([])}let N=k?.chargesWithLedgerChanges?.length?k.chargesWithLedgerChanges[k.chargesWithLedgerChanges.length-1].progress:0,P=(0,w.useCallback)(e=>{D(e)},[D]);return(0,w.useEffect)(()=>{E&&j()},[E,j]),(0,w.useEffect)(()=>{r((0,T.jsxs)(`div`,{className:`flex flex-row gap-x-5 items-center`,children:[(0,T.jsx)(n,{value:N,label:`${N?.toFixed(2)}%`,size:`xl`,animate:N<100,className:`min-w-52`}),(0,T.jsx)(S,{filter:E,setFilter:P,activePage:0,setPage:()=>{},initiallyOpened:!0}),(0,T.jsx)(g,{content:`Expand all accounts`,children:(0,T.jsx)(h,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:()=>c(e=>!e),children:i?(0,T.jsx)(f,{className:`size-5`}):(0,T.jsx)(d,{className:`size-5`})})}),(0,T.jsx)(o,{selected:l,resetMerge:M})]}))},[k,A,E,i,r,c,l,N,P]),(0,T.jsx)(x,{title:`Charges Ledger Validation`,description:`Manage charges`,children:A?(0,T.jsx)(p,{className:`h-10 w-10 animate-spin mr-2 self-center`}):(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(t,{toggleMergeCharge:O,mergeSelectedCharges:new Set(l.map(e=>e.id)),data:k?.chargesWithLedgerChanges.filter(e=>!!e.charge).map(e=>e.charge)??[],isAllOpened:i}),(0,T.jsxs)(`div`,{className:`flex flex-row justify-center my-2`,children:[N>0&&N<100&&(0,T.jsx)(u,{}),N===100&&!k?.chargesWithLedgerChanges.filter(e=>!!e.charge).length&&(0,T.jsx)(e,{radius:`xl`,size:`xl`,color:`green`,children:(0,T.jsx)(v,{})})]})]})})};export{E as n,C as t};