import { useTranslation } from "react-i18next"; import type { CategoryBreakdownItem } from "../../shared/types"; const cadFormatter = (value: number) => new Intl.NumberFormat("en-CA", { style: "currency", currency: "CAD", maximumFractionDigits: 0 }).format(value); interface CategoryTableProps { data: CategoryBreakdownItem[]; hiddenCategories?: Set; } export default function CategoryTable({ data, hiddenCategories }: CategoryTableProps) { const { t } = useTranslation(); const visibleData = hiddenCategories?.size ? data.filter((d) => !hiddenCategories.has(d.category_name)) : data; if (visibleData.length === 0) { return (
{t("dashboard.noData")}
); } const grandTotal = visibleData.reduce((sum, row) => sum + row.total, 0); return (
{visibleData.map((row) => ( ))}
{t("budget.category")} {t("common.total")} %
{row.category_name} {cadFormatter(row.total)} {grandTotal !== 0 ? `${((row.total / grandTotal) * 100).toFixed(1)}%` : "—"}
{t("common.total")} {cadFormatter(grandTotal)} 100%
); }