import React from 'react'; import { CreditCard, Trash2, Star, Banknote, Building2, FileCheck } from 'lucide-react'; import { Button } from './ui/button'; /** * Card brand icon mapping */ const getBrandIcon = (brand) => { const brandLower = brand?.toLowerCase(); // Return text abbreviation for known brands switch (brandLower) { case 'visa': return 'VISA'; case 'mastercard': return 'MC'; case 'amex': case 'american_express': return 'AMEX'; case 'discover': return 'DISC'; default: return null; } }; /** * Get icon for payment method type */ const getPaymentTypeIcon = (paymentType) => { switch (paymentType) { case 'cash': return Banknote; case 'bank_transfer': return Building2; case 'check': return FileCheck; default: return CreditCard; } }; /** * Format payment type for display */ const formatPaymentType = (paymentType) => { switch (paymentType) { case 'cash': return 'Cash'; case 'bank_transfer': return 'Bank Transfer'; case 'check': return 'Check'; case 'card': return 'Card'; default: return paymentType; } }; /** * PaymentMethodCard - Displays a single payment method */ const PaymentMethodCard = ({ method, onSetDefault, onDelete, loading = false, showActions = true, }) => { const PaymentIcon = getPaymentTypeIcon(method.payment_type); const brandAbbr = method.card_brand ? getBrandIcon(method.card_brand) : null; const isExpired = method.card_exp_year && method.card_exp_month && new Date(method.card_exp_year, method.card_exp_month) < new Date(); return (
{/* Payment Method Icon */}
{/* Payment Method Details */}
{method.payment_type === 'card' ? ( <>
{brandAbbr && ( {brandAbbr} )} {method.card_brand ? method.card_brand.charAt(0).toUpperCase() + method.card_brand.slice(1) : 'Card'} •••• {method.card_last4 || '****'} {method.is_default && ( Default )}

{isExpired ? 'Expired' : 'Expires'} {method.card_exp_month?.toString().padStart(2, '0')}/{method.card_exp_year?.toString().slice(-2)} {method.card_funding && ( ({method.card_funding}) )}

) : ( <>
{formatPaymentType(method.payment_type)} {method.is_default && ( Default )}
{method.manual_notes && (

{method.manual_notes}

)} )}
{/* Actions */} {showActions && (
{!method.is_default && ( )}
)}
); }; export default PaymentMethodCard;