"use client"; import { useEffect, useState } from "react"; import { AppShell } from "@/components/AppShell"; import { EmptyState } from "@/components/EmptyState"; import { SectionCard } from "@/components/SectionCard"; import { StatusBadge } from "@/components/StatusBadge"; import { fetchJson } from "@/lib/client"; import type { DashboardResponse } from "@/lib/types"; export function DashboardClient() { const [data, setData] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [message, setMessage] = useState(null); async function loadDashboard() { setLoading(true); setError(null); try { const response = await fetchJson("/api/dashboard"); setData(response); } catch (loadError) { setError(loadError instanceof Error ? loadError.message : "Failed to load dashboard."); } finally { setLoading(false); } } async function seedSampleData() { try { const response = await fetchJson<{ seeded: boolean; reason?: string }>("/api/seed", { method: "POST" }); setMessage(response.seeded ? "Sample team loaded." : response.reason ?? "Seed skipped."); await loadDashboard(); } catch (seedError) { setError(seedError instanceof Error ? seedError.message : "Failed to seed data."); } } useEffect(() => { void loadDashboard(); }, []); return ( void seedSampleData()}> Load Sample Team } > {message ?
{message}
: null} {error ?
{error}
: null} {loading ? ( ) : data && data.rosterCount > 0 ? ( <>
Rostered Players {data.rosterCount}
Active Today {data.activePlayers}
Pitchers Available {data.availablePitchers}
Need Rest {data.needsRest}
{data.recentPitching.map((entry) => (

{entry.playerName}

{entry.lastPitchedDate ? `${entry.pitchCount} pitches on ${entry.lastPitchedDate}` : "No pitching history recorded yet."}

{entry.daysSinceLastAppearance === null ? "No history" : `${entry.daysSinceLastAppearance} day(s) since last outing`}
))}
) : ( void seedSampleData()}> Load Sample Team } /> )}
); }