import{n as e,t}from"./business-ledger-filters-DP8nBc4J.js";import{$n as n,Eu as r,Nl as i,Od as a,Pd as o,Qa as s,ps as c,rr as l,tr as u,zd as d}from"./index-Q5R6-AeA.js";import{t as f}from"./use-url-query-Cos8nKH-.js";import{t as p}from"./business-extended-info-T-v_vId3.js";var m=d(o(),1),h=r(),g=({businessId:r})=>{let{businessId:o}=a(),{get:d}=f(),{setFiltersContext:g}=(0,m.useContext)(u),v=r||o,[y,b]=(0,m.useState)(d(`ledgerRecordsFilters`)?{...JSON.parse(decodeURIComponent(d(`ledgerRecordsFilters`))),businessIDs:v?[v]:[]}:{businessIDs:v?[v]:[]}),[{data:x,fetching:S}]=i({query:s,variables:{filters:y}});(0,m.useEffect)(()=>{g((0,h.jsx)(t,{filter:y,setFilter:b}))},[x,y,g,b]);let C=x?.businessTransactionsSumFromLedgerRecords.__typename===`CommonError`?void 0:x?.businessTransactionsSumFromLedgerRecords.businessTransactionsSum,w=C?[...C].sort((e,t)=>e.business.name.localeCompare(t.business.name)):[];return S?(0,h.jsx)(l,{}):(0,h.jsx)(n,{moreInfo:e=>(0,h.jsx)(p,{businessID:e.business.id,filter:y}),striped:!0,highlightOnHover:!0,stickyHeader:!0,items:w,columns:[{title:`Business Name`,value:e=>e.business.name},{title:`Debit`,value:e=>e.debit.formatted,style:{whiteSpace:`nowrap`}},{title:`Credit`,value:e=>e.credit.formatted,style:{whiteSpace:`nowrap`}},{title:`Total`,value:t=>t.total.raw&&(t.total.raw<-1e-4||t.total.raw>1e-4)?(0,h.jsx)(e,{color:t.total.raw>0?`green`:`red`,children:t.total.formatted}):t.total.formatted,style:{whiteSpace:`nowrap`}},..._(c.Eur),..._(c.Usd),..._(c.Gbp),..._(c.Cad),..._(c.Jpy),..._(c.Aud),..._(c.Sek)]})};function _(t){return[{title:`${t} Debit`,value:e=>e.foreignCurrenciesSum.find(e=>e.currency===t)?.debit?.formatted,style:{whiteSpace:`nowrap`}},{title:`${t} Credit`,value:e=>e.foreignCurrenciesSum.find(e=>e.currency===t)?.credit?.formatted,style:{whiteSpace:`nowrap`}},{title:`${t} Total`,value:n=>{let r=n.foreignCurrenciesSum.find(e=>e.currency===t);return r?.total?.raw&&(r.total.raw<-1e-4||r.total.raw>1e-4)?(0,h.jsx)(e,{color:r.total.raw>0?`green`:`red`,children:r.total.formatted}):r?.total?.formatted},style:{whiteSpace:`nowrap`}}]}export{g as BusinessLedgerRecordsSingle};