import { GroupKey, ReportData } from "../../features/report"; import { extractFilteredTransactions, aggregateTransactions, } from "../report.helpers"; export interface PayeeItem { name: string; amount: number; } export function extractTopPayees( reportData: ReportData, flow: "outflows" | "inflows", selectedPeriodId?: string | null, selectedGroupKey?: GroupKey | null ): { items: PayeeItem[]; total: number } { const txns = extractFilteredTransactions(reportData, selectedPeriodId, selectedGroupKey); const { items, total } = aggregateTransactions(txns, (txn) => { if (txn.payee && txn.payee.name) { return [txn.payee.name]; } return []; }); return { items, total, }; }