'use client';

import { useState } from "react";
import FilterTahunAngkatan from "@/components/FilterTahunAngkatan";
import FilterJenisPrestasi from "@/components/FilterJenisPrestasi";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import TotalPrestasiChart from "@/components/charts/TotalPrestasiChart";
import TotalPrestasiPieChart from "@/components/charts/TotalPrestasiPieChart";
import TingkatPrestasiChart from "@/components/charts/TingkatPrestasiChart";
import TingkatPrestasiPieChart from "@/components/charts/TingkatPrestasiPieChart";
import JenisPendaftaranPrestasiChart from "@/components/charts/JenisPendaftaranPrestasiChart";
import JenisPendaftaranPrestasiPieChart from "@/components/charts/JenisPendaftaranPrestasiPieChart";
import AsalDaerahPrestasiChart from "@/components/charts/AsalDaerahPrestasiChart";
import IPKPrestasiChart from "@/components/charts/IPKPrestasiChart";

export default function BerprestasiMahasiswaPage() {
    const [selectedYear, setSelectedYear] = useState<string>("all");
    const [selectedJenisPrestasi, setSelectedJenisPrestasi] = useState<string>("Akademik");
  
    return (
      <div className="container mx-auto p-4 space-y-6">
        <h1 className="text-3xl font-bold mb-4">Mahasiswa Berprestasi</h1>
        
        <div className="mb-4">
          <p className="text-gray-600 dark:text-gray-300">
            Mahasiswa yang mendapatkan prestasi akademik dan non akademik di program studi Informatika Fakultas Teknik Universitas Tanjungpura.
          </p>
        </div>
  
        <Card className="bg-white dark:bg-slate-900 shadow-lg dark:text-white">
          <CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
            <CardTitle className="text-sm font-medium dark:text-white">
              Filter Data
            </CardTitle>
          </CardHeader>
          <CardContent>
            <div className="flex flex-col sm:flex-row items-start sm:items-center gap-4 sm:space-x-4">
              <FilterTahunAngkatan 
                selectedYear={selectedYear}
                onYearChange={setSelectedYear}
              />
              <FilterJenisPrestasi
                selectedJenisPrestasi={selectedJenisPrestasi}
                onJenisPrestasiChange={setSelectedJenisPrestasi}
              />
            </div>
          </CardContent>
        </Card>

        {selectedYear === "all" ? (
        <>
          <TotalPrestasiChart selectedJenisPrestasi={selectedJenisPrestasi} />
          <TingkatPrestasiChart selectedJenisPrestasi={selectedJenisPrestasi} />
          <JenisPendaftaranPrestasiChart selectedJenisPrestasi={selectedJenisPrestasi} />
        </>
        ) : (
          <>
            <TotalPrestasiPieChart 
              selectedYear={selectedYear}
              selectedJenisPrestasi={selectedJenisPrestasi}
            />
            <TingkatPrestasiPieChart 
              selectedYear={selectedYear}
              selectedJenisPrestasi={selectedJenisPrestasi}
            />
            <JenisPendaftaranPrestasiPieChart 
              selectedYear={selectedYear}
              selectedJenisPrestasi={selectedJenisPrestasi}
            />
          </>
        )}

        <AsalDaerahPrestasiChart selectedYear={selectedYear} selectedJenisPrestasi={selectedJenisPrestasi} />

        {selectedYear === "all" && (
          <IPKPrestasiChart selectedJenisPrestasi={selectedJenisPrestasi} />
        )}
      </div>
    );
  }