"use client" import { useState } from "react" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table" import { Search, Mail, Phone } from "lucide-react" type Patient = { id: string name: string email: string phone: string | null medicalHistory: string | null appointments: Array<{ id: string date: Date status: string service: { name: string } }> } type DentistPatientsTableProps = { patients: Patient[] } export function DentistPatientsTable({ patients }: DentistPatientsTableProps) { const [searchQuery, setSearchQuery] = useState("") const filteredPatients = patients.filter((patient) => { const query = searchQuery.toLowerCase() return ( patient.name.toLowerCase().includes(query) || patient.email.toLowerCase().includes(query) ) }) return ( My Patients Total: {patients.length} patients
setSearchQuery(e.target.value)} className="pl-8" />
Patient Name Contact Total Visits Last Visit Actions {filteredPatients.length === 0 ? ( No patients found ) : ( filteredPatients.map((patient) => { const completedVisits = patient.appointments.filter( (apt) => apt.status === "completed" ).length const lastVisit = patient.appointments[0] return ( {patient.name}
{patient.email}
{patient.phone && (
{patient.phone}
)}

{patient.appointments.length} total

{completedVisits} completed

{lastVisit ? (

{new Date(lastVisit.date).toLocaleDateString()}

{lastVisit.service.name}

) : ( "-" )}
) }) )}
) }