"use client"; import { RiStore2Line } from "@remixicon/react"; import MoneyValues from "@/components/money-values"; import { Badge } from "@/components/ui/badge"; 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 { Progress } from "../ui/progress"; type EstablishmentsListProps = { establishments: TopEstabelecimentosData["establishments"]; }; const buildInitials = (value: string) => { const parts = value.trim().split(/\s+/).filter(Boolean); if (parts.length === 0) return "ES"; if (parts.length === 1) { const firstPart = parts[0]; return firstPart ? firstPart.slice(0, 2).toUpperCase() : "ES"; } const firstChar = parts[0]?.[0] ?? ""; const secondChar = parts[1]?.[0] ?? ""; return `${firstChar}${secondChar}`.toUpperCase() || "ES"; }; export function EstablishmentsList({ establishments, }: EstablishmentsListProps) { if (establishments.length === 0) { return ( Top Estabelecimentos } title="Nenhum estabelecimento encontrado" description="Quando houver compras registradas, elas aparecerão aqui." /> ); } const maxCount = Math.max(...establishments.map((e) => e.count)); return ( Top Estabelecimentos por Frequência {establishments.map((establishment, index) => { const _initials = buildInitials(establishment.name); return ( {/* Rank number - same size as icon containers */} {index + 1} {/* Name and categories */} {establishment.name} {establishment.categories .slice(0, 2) .map((cat, catIndex) => ( {cat.name} ))} {/* Value and stats */} {establishment.count}x • Média:{" "} {/* Progress bar */} ); })} ); }