"use client"; import { RiDeleteBin5Line, RiFileList2Line, RiPencilLine, } from "@remixicon/react"; import Link from "next/link"; import { CategoryIconBadge } from "@/shared/components/entity-avatar"; import MoneyValues from "@/shared/components/money-values"; import { Card, CardContent, CardFooter } from "@/shared/components/ui/card"; import { Progress } from "@/shared/components/ui/progress"; import { cn } from "@/shared/utils/ui"; import type { Budget } from "./types"; interface BudgetCardProps { budget: Budget; onEdit: (budget: Budget) => void; onRemove: (budget: Budget) => void; } const buildUsagePercent = (spent: number, limit: number) => { if (limit <= 0) { return spent > 0 ? 100 : 0; } const percent = (spent / limit) * 100; return Math.min(Math.max(percent, 0), 100); }; const formatCategoryName = (budget: Budget) => budget.category?.name ?? "Categoria removida"; export function BudgetCard({ budget, onEdit, onRemove }: BudgetCardProps) { const { amount: limit, spent } = budget; const exceeded = spent > limit && limit >= 0; const difference = Math.abs(spent - limit); const usagePercent = buildUsagePercent(spent, limit); const remaining = Math.max(limit - spent, 0); return (

{formatCategoryName(budget)}

{exceeded ? "Excedido em" : "Disponível"}
Orçamento
Gasto
{usagePercent.toFixed(1)}% utilizado
{budget.category && ( detalhes )}
); }