import { useState, useEffect, useRef } from "react"; import { FileText, Share2, Calendar, Smile, Meh, ChevronRight, Loader2 } from "lucide-react"; type MoodKey = "calm" | "cooperative" | "anxious" | "wiggly"; const MOOD_CONFIG: Record = { calm: { icon: Smile, label: "Calm & Relaxed", color: "text-green-700", bg: "bg-green-100" }, cooperative: { icon: Smile, label: "Cooperative", color: "text-blue-700", bg: "bg-blue-100" }, anxious: { icon: Meh, label: "Anxious", color: "text-amber-700", bg: "bg-amber-100" }, wiggly: { icon: Meh, label: "Wiggly", color: "text-purple-700", bg: "bg-purple-100" }, }; interface Appointment { id: string; petId: string; serviceId: string; groomerId: string | null; date: string; time: string; status: string; petName?: string; serviceName?: string; groomerName?: string; reportCardId?: string; } interface Props { sessionId: string | null; } export function ReportCards({ sessionId }: Props) { const [appointments, setAppointments] = useState([]); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); const [selectedCard, setSelectedCard] = useState(null); const fetchReportCardsRef = useRef<() => Promise>(async () => { setIsLoading(true); setError(null); try { const response = await fetch("/api/portal/appointments", { headers: { "X-Impersonation-Session-Id": sessionId ?? "" }, }); if (response.ok) { const data = await response.json(); const allAppointments: Appointment[] = data.appointments || data || []; const reportCardAppointments = allAppointments.filter( (appt) => appt.reportCardId ); setAppointments(reportCardAppointments); } else { setError("Failed to load report cards."); } } catch { setError("Failed to load report cards. Please try again."); } finally { setIsLoading(false); } }); useEffect(() => { void fetchReportCardsRef.current(); }, [sessionId]); if (isLoading) { return (
Loading report cards...
); } if (error) { return (

{error}

); } if (appointments.length === 0) { return (

No Report Cards Yet

Report cards from your grooming visits will appear here after your appointments.

); } if (selectedCard) { return setSelectedCard(null)} />; } return (

Grooming report cards from your recent visits

{appointments.map((card) => { const moodKey: MoodKey = "cooperative"; const mood = MOOD_CONFIG[moodKey]; const MoodIcon = mood.icon; return ( ); })}
); } function ReportCardDetail({ card, onBack }: { card: Appointment; onBack: () => void }) { const moodKey: MoodKey = "cooperative"; const mood = MOOD_CONFIG[moodKey]; const MoodIcon = mood.icon; return (
{/* Header */}

{card.petName || "Pet"}'s Grooming Report

{new Date(card.date).toLocaleDateString("en-US", { weekday: "long", month: "long", day: "numeric", year: "numeric", })} {card.groomerName ? ` ยท Groomer: ${card.groomerName}` : ""}

{/* Before & After */}

Before & After

Before

Photo placeholder

Before photo description not available.

After

Photo placeholder

After photo description not available.

{/* Services */}

Services Performed

{card.serviceName || "Grooming"}
{/* Behavior */}

Behavior & Mood

{mood.label}
{/* Groomer's Note */}

A Note from {card.groomerName || "Your Groomer"}

"Report card details are not yet available. Please check back after your visit."

{/* Next Appointment CTA */}

Book your next visit

Schedule your next grooming appointment

); }