import { redirect } from "next/navigation";
import { AdminService } from "@/services/admin-service";
import { TeamDetailClientWrapper } from "@/components/admin";

interface TeamDetailPageProps {
  params: Promise<{
    teamId: string;
  }>;
}

export default async function TeamDetailPage({ params }: TeamDetailPageProps) {
  // Await params before using
  const { teamId } = await params;

  try {
    // Charger les données côté serveur
    const allTeamsStats = await AdminService.getTeamsStats();
    const foundTeamStats = allTeamsStats.find((t) => t.teamId === teamId);

    if (!foundTeamStats) {
      redirect("/admin");
    }

    return <TeamDetailClientWrapper team={foundTeamStats} teamId={teamId} />;
  } catch (error) {
    console.error("Failed to load team data:", error);
    return (
      <div className="min-h-screen bg-gradient-to-br from-slate-950 via-slate-900 to-slate-950 flex items-center justify-center">
        <div className="text-white text-xl text-red-500">
          Erreur lors du chargement des détails de l'équipe
        </div>
      </div>
    );
  }
}
