"use client"; import { useState } from "react"; import { Button } from "@/components/ui/button"; import { cn } from "@/lib/utils"; interface Client { 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?: Array<{ id: string; status: string; startDate: string; endDate: string; remainingHours: number | null; plan: { id: string; name: string; price: number | string; durationMonths: number; courtHours: number | null; discountPercent: number | string | null; }; }>; _count?: { bookings: number; }; stats?: { totalBookings: number; totalSpent: number; balance: number; }; } interface ClientTableProps { clients: Client[]; onRowClick?: (client: Client) => void; onEdit?: (client: Client) => void; onDelete?: (client: Client) => void; isLoading?: boolean; currentPage: number; totalPages: number; onPageChange: (page: number) => void; } // Loading skeleton for table rows function TableSkeleton() { return ( <> {[...Array(5)].map((_, i) => (
))} ); } export function ClientTable({ clients, onRowClick, onEdit, onDelete, isLoading = false, currentPage, totalPages, onPageChange, }: ClientTableProps) { // Get initials for avatar fallback const getInitials = (firstName: string, lastName: string) => { return `${firstName.charAt(0)}${lastName.charAt(0)}`.toUpperCase(); }; // Get membership badge info const getMembershipBadge = (client: Client) => { const activeMembership = client.memberships?.[0]; if (activeMembership && activeMembership.status === "ACTIVE") { return { label: activeMembership.plan.name, className: "bg-accent-100 text-accent-700 border-accent-300", }; } return { label: "Sin membresia", className: "bg-gray-100 text-gray-600 border-gray-200", }; }; if (isLoading) { return (
Cliente Email Telefono Membresia Reservas Acciones
); } if (clients.length === 0) { return (

No hay clientes

Agrega tu primer cliente para comenzar

); } return (
{clients.map((client) => { const membershipBadge = getMembershipBadge(client); return ( onRowClick?.(client)} > {/* Client Name with Avatar */} {/* Email */} {/* Phone */} {/* Membership Status */} {/* Bookings Count */} {/* Actions */} ); })}
Cliente Email Telefono Membresia Reservas Acciones
{client.avatar ? ( {`${client.firstName} ) : (
{getInitials(client.firstName, client.lastName)}
)}

{client.firstName} {client.lastName}

{client.level && (

Nivel: {client.level}

)}
{client.email || ( - )} {client.phone || ( - )} {membershipBadge.label} {client._count?.bookings || 0}
e.stopPropagation()} >
{/* Pagination */} {totalPages > 1 && (
Pagina {currentPage} de {totalPages}
)}
); }