"use client"; import { RiArrowDownSFill, RiArrowUpSFill } from "@remixicon/react"; import { Tooltip, TooltipContent, TooltipTrigger, } from "@/components/ui/tooltip"; import { formatCurrency, formatPercentageChange } from "@/lib/relatorios/utils"; import { cn } from "@/lib/utils/ui"; interface CategoryCellProps { value: number; previousValue: number; categoryType: "despesa" | "receita"; isFirstMonth: boolean; } export function CategoryCell({ value, previousValue, categoryType, isFirstMonth, }: CategoryCellProps) { const percentageChange = !isFirstMonth && previousValue !== 0 ? ((value - previousValue) / previousValue) * 100 : null; const absoluteChange = !isFirstMonth ? value - previousValue : null; const isIncrease = percentageChange !== null && percentageChange > 0; const isDecrease = percentageChange !== null && percentageChange < 0; // Despesa: aumento é ruim (vermelho), diminuição é bom (verde) // Receita: aumento é bom (verde), diminuição é ruim (vermelho) const isPositive = categoryType === "receita" ? isIncrease : isDecrease; const isNegative = categoryType === "receita" ? isDecrease : isIncrease; return (
{formatCurrency(value)} {!isFirstMonth && percentageChange !== null && (
{isIncrease && } {isDecrease && } {formatPercentageChange(percentageChange)}
)}
{formatCurrency(value)}
{!isFirstMonth && absoluteChange !== null && ( <>
Mês anterior: {formatCurrency(previousValue)}
Diferença:{" "} {absoluteChange >= 0 ? `+${formatCurrency(absoluteChange)}` : formatCurrency(absoluteChange)}
)}
); }