"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 type { CategoryReportData, CategoryReportItem, } from "@/lib/relatorios/types"; import { formatCurrency, 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[]; colorIndex: number; } function CategoryCard({ category, periods, colorIndex }: CategoryCardProps) { const periodParam = formatPeriodForUrl(periods[periods.length - 1]); return ( {category.name} {periods.map((period, periodIndex) => { const monthData = category.monthlyData.get(period); const isFirstMonth = periodIndex === 0; return (
{formatPeriodLabel(period)}
); })}
Total {formatCurrency(category.total)}
); } interface SectionProps { title: string; categories: CategoryReportItem[]; periods: string[]; colorIndexOffset: number; total: number; } function Section({ title, categories, periods, colorIndexOffset, total, }: SectionProps) { if (categories.length === 0) { return null; } return (
{title} {formatCurrency(total)}
{categories.map((category, index) => ( ))}
); } export function CategoryReportCards({ data }: CategoryReportCardsProps) { const { categories, periods } = data; // 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 */}
); }