import { useTranslation } from "react-i18next"; import type { MonthlyTrendItem } from "../../shared/types"; const cadFormatter = (value: number) => new Intl.NumberFormat("en-CA", { style: "currency", currency: "CAD", maximumFractionDigits: 0 }).format(value); function formatMonth(month: string): string { const [year, m] = month.split("-"); const date = new Date(Number(year), Number(m) - 1); return date.toLocaleDateString("default", { month: "short", year: "2-digit" }); } interface MonthlyTrendsTableProps { data: MonthlyTrendItem[]; } export default function MonthlyTrendsTable({ data }: MonthlyTrendsTableProps) { const { t } = useTranslation(); if (data.length === 0) { return (
| {t("reports.pivot.month")} | {t("dashboard.income")} | {t("dashboard.expenses")} | {t("dashboard.net")} |
|---|---|---|---|
| {formatMonth(row.month)} | {cadFormatter(row.income)} | {cadFormatter(row.expenses)} | = 0 ? "text-[var(--positive)]" : "text-[var(--negative)]"}`}> {cadFormatter(row.income - row.expenses)} |
| {t("common.total")} | {cadFormatter(totals.income)} | {cadFormatter(totals.expenses)} | = 0 ? "text-[var(--positive)]" : "text-[var(--negative)]"}`}> {cadFormatter(totals.income - totals.expenses)} |