'use client' import { CreditCard } from '@/lib/types' import { formatCurrency, getCardUtilization, getDaysUntil, calculateNextClosingDate, calculateNextDueDate } from '@/lib/utils' import { Pencil, Trash2 } from 'lucide-react' interface CreditCardWidgetProps { card: CreditCard onEdit: () => void onDelete: () => void } export function CreditCardWidget({ card, onEdit, onDelete }: CreditCardWidgetProps) { const utilization = getCardUtilization(card.currentBalance, card.creditLimit) const nextClosing = calculateNextClosingDate(card.closingDay) const nextDue = calculateNextDueDate(card.dueDay) const daysUntilClosing = getDaysUntil(nextClosing) const daysUntilDue = getDaysUntil(nextDue) const getUtilizationColor = (util: number): string => { if (util < 30) return 'bg-emerald-500' if (util < 70) return 'bg-amber-500' return 'bg-rose-500' } const getUtilizationTextColor = (util: number): string => { if (util < 30) return 'text-emerald-400' if (util < 70) return 'text-amber-400' return 'text-rose-400' } return (
{/* Decorative circles */}
{/* Header with card name and actions */}

{card.name}

{/* Card number */}

**** **** **** {card.lastFourDigits}

{/* Balance */}

Balance actual

{formatCurrency(card.currentBalance)}

{/* Utilization badge */}
{utilization.toFixed(0)}% usado
de {formatCurrency(card.creditLimit)}
{/* Footer with closing and due dates */}
Cierre {card.closingDay} ({daysUntilClosing === 0 ? 'hoy' : daysUntilClosing > 0 ? `en ${daysUntilClosing} días` : `hace ${Math.abs(daysUntilClosing)} días`})
Vencimiento {card.dueDay} ({daysUntilDue === 0 ? 'hoy' : daysUntilDue > 0 ? `en ${daysUntilDue} días` : `hace ${Math.abs(daysUntilDue)} días`})
) } /** * Ajusta el brillo de un color hexadecimal * @param color - Color en formato hex (#RRGGBB) * @param amount - Cantidad a ajustar (negativo para oscurecer, positivo para aclarar) * @returns Color ajustado en formato hex */ function adjustColor(color: string, amount: number): string { const hex = color.replace('#', '') const r = Math.max(0, Math.min(255, parseInt(hex.substring(0, 2), 16) + amount)) const g = Math.max(0, Math.min(255, parseInt(hex.substring(2, 4), 16) + amount)) const b = Math.max(0, Math.min(255, parseInt(hex.substring(4, 6), 16) + amount)) return `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}` }