"use client"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { formatCurrency, formatDate, cn } from "@/lib/utils"; interface ClientMembership { id: string; status: string; startDate: string; endDate: string; remainingHours: number | null; plan: { id: string; name: string; price: number | string; durationMonths: number; courtHours: number | null; }; } interface ClientDetail { id: string; firstName: string; lastName: string; email: string | null; phone: string | null; avatar?: string | null; level: string | null; notes: string | null; isActive: boolean; createdAt: string; memberships?: ClientMembership[]; _count?: { bookings: number; }; stats?: { totalBookings: number; totalSpent: number; balance: number; }; } interface ClientDetailDialogProps { client: ClientDetail; onClose: () => void; onEdit?: () => void; onAssignMembership?: () => void; onAddBalance?: () => void; } export function ClientDetailDialog({ client, onClose, onEdit, onAssignMembership, onAddBalance, }: ClientDetailDialogProps) { // Get initials for avatar fallback const getInitials = (firstName: string, lastName: string) => { return `${firstName.charAt(0)}${lastName.charAt(0)}`.toUpperCase(); }; // Get active membership const activeMembership = client.memberships?.find( (m) => m.status === "ACTIVE" ); // Calculate hours used if there's an active membership with hours const hoursTotal = activeMembership?.plan.courtHours || 0; const hoursRemaining = activeMembership?.remainingHours || 0; const hoursUsed = hoursTotal - hoursRemaining; // Handle click outside to close const handleOverlayClick = (e: React.MouseEvent) => { if (e.target === e.currentTarget) { onClose(); } }; return (
Nivel: {client.level}
)}Sin membresia activa
{onAssignMembership && ( )}{client.stats?.totalBookings || client._count?.bookings || 0}
Reservas
{formatCurrency(client.stats?.totalSpent || 0)}
Total Gastado
= 0 ? "text-green-600" : "text-red-600" )} > {formatCurrency(client.stats?.balance || 0)}
Saldo
{client.notes}