import { RiArrowDownLine, RiArrowDownSFill, RiArrowUpLine, RiArrowUpSFill, RiCashLine, RiIncreaseDecreaseLine, RiSubtractLine, } from "@remixicon/react"; import { Card, CardAction, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card"; import type { DashboardCardMetrics } from "@/lib/dashboard/metrics"; import MoneyValues from "../money-values"; type SectionCardsProps = { metrics: DashboardCardMetrics; }; type Trend = "up" | "down" | "flat"; const TREND_THRESHOLD = 0.005; const CARDS = [ { label: "Receitas", key: "receitas", icon: RiArrowUpLine, invertTrend: false, }, { label: "Despesas", key: "despesas", icon: RiArrowDownLine, invertTrend: true, }, { label: "Balanço", key: "balanco", icon: RiIncreaseDecreaseLine, invertTrend: false, }, { label: "Previsto", key: "previsto", icon: RiCashLine, invertTrend: false }, ] as const; const TREND_ICONS = { up: RiArrowUpSFill, down: RiArrowDownSFill, flat: RiSubtractLine, } as const; const getTrend = (current: number, previous: number): Trend => { const diff = current - previous; if (diff > TREND_THRESHOLD) return "up"; if (diff < -TREND_THRESHOLD) return "down"; return "flat"; }; const getPercentChange = (current: number, previous: number): string => { const EPSILON = 0.01; // Considera valores menores que 1 centavo como zero if (Math.abs(previous) < EPSILON) { if (Math.abs(current) < EPSILON) return "0%"; return "—"; } const change = ((current - previous) / Math.abs(previous)) * 100; return Number.isFinite(change) && Math.abs(change) < 1000000 ? `${change > 0 ? "+" : ""}${change.toFixed(1)}%` : "—"; }; const getTrendColor = (trend: Trend, invertTrend: boolean): string => { if (trend === "flat") return ""; const isPositive = invertTrend ? trend === "down" : trend === "up"; return isPositive ? "text-success border-success" : "text-destructive border-destructive"; }; export function SectionCards({ metrics }: SectionCardsProps) { return (