import type { CSSProperties } from "react"; import MoneyValues from "@/components/money-values"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import type { PagadorMonthlyBreakdown } from "@/lib/pagadores/details"; import { cn } from "@/lib/utils/ui"; const segmentConfig = { card: { label: "Cartões", color: "bg-violet-500", }, boleto: { label: "Boletos", color: "bg-amber-500", }, instant: { label: "Pix/Débito/Dinheiro", color: "bg-emerald-500", }, } as const; type PagadorMonthlySummaryCardProps = { periodLabel: string; breakdown: PagadorMonthlyBreakdown; }; export function PagadorMonthlySummaryCard({ periodLabel, breakdown, }: PagadorMonthlySummaryCardProps) { const splittableEntries = ( Object.keys(segmentConfig) as Array ).map((key) => ({ key, ...segmentConfig[key], value: breakdown.paymentSplits[key], })); const totalBase = splittableEntries.reduce( (sum, entry) => sum + entry.value, 0, ); let offset = 0; return ( Totais do mês

{periodLabel} - Despesas por forma de pagamento

Total
{splittableEntries.map((entry) => { const percent = totalBase > 0 ? Math.max((entry.value / totalBase) * 100, 0) : 0; const style: CSSProperties = { width: `${percent}%`, left: `${offset}%`, }; offset += percent; return ( ); })}
{splittableEntries.map((entry) => { const percent = totalBase > 0 ? Math.round((entry.value / totalBase) * 100) : 0; return (
{entry.label} {percent}% das despesas
); })}
); }