"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 metrics = limitTotal === null || used === null || available === null ? null : [ { label: "Limite Total", value: limitTotal }, { label: "Em uso", value: used }, { label: "Disponível", value: available }, ]; const actions = [ { label: "editar", icon: , onClick: onEdit, className: "text-primary", }, { label: "ver fatura", icon: , onClick: onInvoice, className: "text-primary", }, { label: "remover", icon: , onClick: onRemove, className: "text-destructive", }, ]; return ( {logoPath ? ( ) : null} {name} {note ? ( {note} ) : null} {status ? ( {status} ) : null} {brandAsset ? ( ) : ( {brand} )} Fecha dia{" "} {formatDay(closingDay)} Vence dia{" "} {formatDay(dueDay)} {metrics ? ( <> {metrics[0].label} {metrics[1].label} {metrics[2].label} > ) : ( Ainda não há limite registrado para este cartão. )} {actions.map(({ label, icon, onClick, className }) => ( {icon} {label} ))} ); }
Ainda não há limite registrado para este cartão.