"use client"; import { RiChat3Line, RiDeleteBin5Line, RiFileList2Line, RiPencilLine, } from "@remixicon/react"; import Image from "next/image"; import MoneyValues from "@/shared/components/money-values"; import { Card, CardContent, CardFooter, CardHeader, } from "@/shared/components/ui/card"; import { Progress } from "@/shared/components/ui/progress"; import { Tooltip, TooltipContent, TooltipTrigger, } from "@/shared/components/ui/tooltip"; import { resolveCardBrandAsset } from "@/shared/lib/cards/brand-assets"; import { resolveLogoSrc } from "@/shared/lib/logo"; import { cn } from "@/shared/utils/ui"; interface CardItemProps { name: string; brand: string; status: string; closingDay: string; dueDay: string; limit: number | null; limitInUse?: number | null; limitAvailable?: number | null; accountName: string; logo?: string | null; note?: string | null; onEdit?: () => void; onInvoice?: () => void; onRemove?: () => void; } const formatDay = (value: string) => value.padStart(2, "0"); export function CardItem({ name, brand, status, closingDay, dueDay, limit, limitInUse, limitAvailable, accountName: _accountName, logo, note, onEdit, onInvoice, onRemove, }: CardItemProps) { void _accountName; const limitTotal = limit ?? null; const used = limitInUse ?? (limitTotal !== null && limitAvailable != null ? Math.max(limitTotal - limitAvailable, 0) : limitTotal !== null ? 0 : null); const available = limitAvailable ?? (limitTotal !== null && used !== null ? Math.max(limitTotal - used, 0) : null); const usagePercent = limitTotal && limitTotal > 0 && used !== null ? Math.min(Math.max((used / limitTotal) * 100, 0), 100) : 0; const logoPath = resolveLogoSrc(logo); const brandAsset = resolveCardBrandAsset(brand); const isInactive = status?.toLowerCase() === "inativo"; const hasMetrics = limitTotal !== null && used !== null && available !== null; return (
{logoPath ? (
{`Logo
) : null}

{name}

{note ? ( {note} ) : null}
{status ? ( {status} ) : null}
{brandAsset ? (
{`Bandeira
) : ( {brand} )}
Fecha em{" "} dia {formatDay(closingDay)} Vence em{" "} dia {formatDay(dueDay)}
{hasMetrics && available !== null && used !== null && limitTotal !== null ? ( <>
Disponível
Limite total
Em uso
{usagePercent.toFixed(1)}% utilizado
) : (

Ainda não há limite registrado para este cartão.

)}
); }