"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 (
Detalle del Cliente
{/* Profile Section */}
{client.avatar ? ( {`${client.firstName} ) : (
{getInitials(client.firstName, client.lastName)}
)}

{client.firstName} {client.lastName}

{client.isActive ? "Activo" : "Inactivo"}
{client.level && (

Nivel: {client.level}

)}
{client.email && (
{client.email}
)} {client.phone && (
{client.phone}
)}
{/* Membership Section */}

Membresia

{activeMembership ? (
Plan: {activeMembership.plan.name}
Precio: {formatCurrency(Number(activeMembership.plan.price))}
Inicio: {formatDate(activeMembership.startDate)}
Vencimiento: {formatDate(activeMembership.endDate)}
{hoursTotal > 0 && (
Horas usadas: {hoursUsed} / {hoursTotal}h
= hoursTotal ? "bg-red-500" : hoursUsed >= hoursTotal * 0.75 ? "bg-yellow-500" : "bg-accent-500" )} style={{ width: `${Math.min( (hoursUsed / hoursTotal) * 100, 100 )}%`, }} />
)}
) : (

Sin membresia activa

{onAssignMembership && ( )}
)}
{/* Stats Section */}

{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

{/* Notes Section */} {client.notes && (

Notas

{client.notes}

)} {/* Member Since */}
Cliente desde {formatDate(client.createdAt)}
{/* Action Buttons */}
{onEdit && ( )} {activeMembership && onAssignMembership && ( )} {!activeMembership && onAssignMembership && ( )} {onAddBalance && ( )}
); }