"use client"; import MoneyValues from "@/components/money-values"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { WidgetEmptyState } from "@/components/widget-empty-state"; import type { TopEstabelecimentosData } from "@/lib/top-estabelecimentos/fetch-data"; import { buildCategoryInitials, getCategoryBgColor, getCategoryColor, } from "@/lib/utils/category-colors"; import { getIconComponent } from "@/lib/utils/icons"; import { title_font } from "@/public/fonts/font_index"; import { RiPriceTag3Line } from "@remixicon/react"; import { Progress } from "../ui/progress"; type TopCategoriesProps = { categories: TopEstabelecimentosData["topCategories"]; }; export function TopCategories({ categories }: TopCategoriesProps) { if (categories.length === 0) { return ( Principais Categorias } title="Nenhuma categoria encontrada" description="Quando houver despesas categorizadas, elas aparecerão aqui." /> ); } const totalAmount = categories.reduce((acc, c) => acc + c.totalAmount, 0); return ( Principais Categorias {categories.map((category, index) => { const IconComponent = category.icon ? getIconComponent(category.icon) : null; const color = getCategoryColor(index); const bgColor = getCategoryBgColor(index); const initials = buildCategoryInitials(category.name); const percent = totalAmount > 0 ? (category.totalAmount / totalAmount) * 100 : 0; return ( {IconComponent ? ( ) : ( {initials} )} {/* Name and percentage */} {category.name} {percent.toFixed(0)}% do total •{" "} {category.transactionCount}x {/* Value */} {/* Progress bar */} ); })} ); }