"use client"; import { useEffect, useState } from "react"; import Link from "next/link"; import { api } from "@/lib/api/client"; import { PageHeader } from "@/components/dashboard/page-header"; import { StatCard } from "@/components/dashboard/stat-card"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Calendar, Target, TrendingUp, Trophy, ArrowUpRight, } from "lucide-react"; import { FormDonutChart, GoalsTrendChart } from "@/components/manager/TeamCharts"; export function ManagerDashboardClient() { const [activeTab, setActiveTab] = useState("overview"); const [data, setData] = useState<{ nextFixture: Record | null; recentResults: Record[]; stats: { wins: number; draws: number; losses: number; goalsFor: number; played: number; } | null; } | null>(null); const [loading, setLoading] = useState(true); useEffect(() => { api.manager.dashboard().then(setData).finally(() => setLoading(false)); }, []); const stats = data?.stats; const results = (data?.recentResults ?? []) as { result: string; goals_for: number; goals_against: number; opponent_name: string; scheduled_at: string; }[]; const winRate = stats && stats.played > 0 ? Math.round((stats.wins / stats.played) * 100) : 0; return (
View leagues } /> {loading ? (
{[1, 2, 3, 4].map((i) => ( ))}
) : activeTab === "overview" ? ( <>
stats.losses ? "up" : "neutral"} trendLabel={`${stats?.wins ?? 0}W ${stats?.draws ?? 0}D ${stats?.losses ?? 0}L`} /> = 50 ? "up" : "down"} trendLabel="form" />
Result analysis Form and goals trend {results.length > 0 ? (
d.value > 0)} /> ({ matchday: i + 1, gf: r.goals_for, ga: r.goals_against, }))} />
) : (

Complete matches to unlock charts.

)}
Next fixture check Upcoming match {data?.nextFixture ? ( ) : (

No upcoming fixtures. Check{" "} leagues .

)}
Recent results Latest match outcomes {results.map((r, i) => (
vs {r.opponent_name}
{r.goals_for}-{r.goals_against} {r.result}
))} {results.length === 0 && (

No results yet

)}
) : ( {activeTab === "reports" ? "Detailed reports coming soon." : "Activity feed coming soon."} )}
); } function NextFixtureCard({ fixture }: { fixture: Record }) { const home = fixture.home as { name: string } | null; const away = fixture.away as { name: string } | null; const when = (fixture.scheduled_at as string) || (fixture.proposed_scheduled_at as string); return (

{home?.name} vs{" "} {away?.name}

{when && (

{new Date(when).toLocaleString()}

)} {(fixture.status as string)?.replace(/_/g, " ")}
); }