import {
  GraduationCap,
  Users,
  Calendar,
  TrendingUp,
  BarChart3,
} from 'lucide-react';

import { getSupabaseServerClient } from '@kit/supabase/server-client';
import { Card, CardContent, CardHeader, CardTitle } from '@kit/ui/card';

import { createCourseManagementApi } from '@kit/course-management/api';

import { CmsPageShell } from '~/components/cms-page-shell';
import { StatsCard } from '~/components/stats-card';

interface PageProps {
  params: Promise<{ account: string }>;
}

export default async function CourseStatisticsPage({ params }: PageProps) {
  const { account } = await params;
  const client = getSupabaseServerClient();

  const { data: acct } = await client
    .from('accounts')
    .select('id')
    .eq('slug', account)
    .single();

  if (!acct) return <div>Konto nicht gefunden</div>;

  const api = createCourseManagementApi(client);
  const stats = await api.getStatistics(acct.id);

  return (
    <CmsPageShell account={account} title="Kurs-Statistiken">
      <div className="flex w-full flex-col gap-6">
        <div>
          <h1 className="text-2xl font-bold">Statistiken</h1>
          <p className="text-muted-foreground">Übersicht über das Kursangebot</p>
        </div>

        {/* Stat Cards */}
        <div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4">
          <StatsCard
            title="Kurse gesamt"
            value={stats.totalCourses}
            icon={<GraduationCap className="h-5 w-5" />}
          />
          <StatsCard
            title="Aktive Kurse"
            value={stats.openCourses}
            icon={<Calendar className="h-5 w-5" />}
          />
          <StatsCard
            title="Teilnehmer gesamt"
            value={stats.totalParticipants}
            icon={<Users className="h-5 w-5" />}
          />
          <StatsCard
            title="Abgeschlossen"
            value={stats.completedCourses}
            icon={<TrendingUp className="h-5 w-5" />}
          />
        </div>

        {/* Chart Placeholder */}
        <Card>
          <CardHeader>
            <CardTitle className="flex items-center gap-2">
              <BarChart3 className="h-5 w-5" />
              Kursauslastung
            </CardTitle>
          </CardHeader>
          <CardContent>
            <div className="flex h-64 items-center justify-center rounded-md border border-dashed text-muted-foreground">
              Diagramm wird hier angezeigt
            </div>
          </CardContent>
        </Card>

        <Card>
          <CardHeader>
            <CardTitle className="flex items-center gap-2">
              <TrendingUp className="h-5 w-5" />
              Anmeldungen pro Monat
            </CardTitle>
          </CardHeader>
          <CardContent>
            <div className="flex h-64 items-center justify-center rounded-md border border-dashed text-muted-foreground">
              Diagramm wird hier angezeigt
            </div>
          </CardContent>
        </Card>
      </div>
    </CmsPageShell>
  );
}
