"use client"; import Link from "next/link"; import { useMemo } from "react"; import { CategoryIconBadge } from "@/components/categorias/category-icon-badge"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { formatCurrency } from "@/lib/lancamentos/formatting-helpers"; import type { CategoryReportData, CategoryReportItem, } from "@/lib/types/relatorios"; import { formatPeriodLabel } from "@/lib/relatorios/utils"; import { formatPeriodForUrl } from "@/lib/utils/period"; import { CategoryCell } from "./category-cell"; interface CategoryReportCardsProps { data: CategoryReportData; } interface CategoryCardProps { category: CategoryReportItem; periods: string[]; periodCount: number; colorIndex: number; } function CategoryCard({ category, periods, periodCount, colorIndex, }: CategoryCardProps) { const periodParam = formatPeriodForUrl(periods[periods.length - 1]); const averageMonthlyTotal = category.total / periodCount; return ( {category.name} {periods.map((period, periodIndex) => { const monthData = category.monthlyData.get(period); const isFirstMonth = periodIndex === 0; return (
{formatPeriodLabel(period)}
); })}
Média mensal {formatCurrency(averageMonthlyTotal)}
Total {formatCurrency(category.total)}
); } interface SectionProps { title: string; categories: CategoryReportItem[]; periods: string[]; periodCount: number; colorIndexOffset: number; total: number; } function Section({ title, categories, periods, periodCount, colorIndexOffset, total, }: SectionProps) { if (categories.length === 0) { return null; } const averageMonthlyTotal = total / periodCount; return (
{title}
{formatCurrency(total)} Média: {formatCurrency(averageMonthlyTotal)}
{categories.map((category, index) => ( ))}
); } export function CategoryReportCards({ data }: CategoryReportCardsProps) { const { categories, periods } = data; const periodCount = Math.max(periods.length, 1); // Separate categories by type and calculate totals const { receitas, despesas, receitasTotal, despesasTotal } = useMemo(() => { const receitas: CategoryReportItem[] = []; const despesas: CategoryReportItem[] = []; let receitasTotal = 0; let despesasTotal = 0; for (const category of categories) { if (category.type === "receita") { receitas.push(category); receitasTotal += category.total; } else { despesas.push(category); despesasTotal += category.total; } } return { receitas, despesas, receitasTotal, despesasTotal }; }, [categories]); return (
{/* Despesas Section */}
{/* Receitas Section */}
); }