import { useTranslation } from "react-i18next"; import { CalendarClock } from "lucide-react"; import type { CartesSeasonality } from "../../../shared/types"; export interface SeasonalityCardProps { seasonality: CartesSeasonality; referenceYear: number; referenceMonth: number; } function formatCurrency(amount: number, language: string): string { return new Intl.NumberFormat(language === "fr" ? "fr-CA" : "en-CA", { style: "currency", currency: "CAD", maximumFractionDigits: 0, }).format(amount); } function formatPct(pct: number, language: string, signed = true): string { return new Intl.NumberFormat(language === "fr" ? "fr-CA" : "en-CA", { style: "percent", maximumFractionDigits: 1, signDisplay: signed ? "always" : "auto", }).format(pct / 100); } function formatMonthYear(year: number, month: number, language: string): string { return new Intl.DateTimeFormat(language === "fr" ? "fr-CA" : "en-CA", { month: "long", year: "numeric", }).format(new Date(year, month - 1, 1)); } export default function SeasonalityCard({ seasonality, referenceYear, referenceMonth, }: SeasonalityCardProps) { const { t, i18n } = useTranslation(); const language = i18n.language; const { referenceAmount, historicalYears, historicalAverage, deviationPct } = seasonality; const refLabel = formatMonthYear(referenceYear, referenceMonth, language); return (

{t("reports.cartes.seasonalityTitle")}

{historicalYears.length === 0 ? (
{t("reports.cartes.seasonalityEmpty")}
) : (
{refLabel} {formatCurrency(referenceAmount, language)}
{historicalYears.map((y) => (
{y.year} {formatCurrency(y.amount, language)}
))} {historicalAverage !== null && (
{t("reports.cartes.seasonalityAverage")} {formatCurrency(historicalAverage, language)}
)}
{deviationPct !== null && (
5 ? "text-[var(--negative)]" : deviationPct < -5 ? "text-[var(--positive)]" : "text-[var(--muted-foreground)]" }`} > {t("reports.cartes.seasonalityDeviation", { pct: formatPct(deviationPct, language), })}
)}
)}
); }