import { redirect } from "next/navigation";
import {
  isUserAuthenticated,
  getServerUserEvaluation,
  getServerSkillCategories,
  getServerTeams,
} from "@/lib/server-auth";
import { EvaluationClientWrapper } from "@/components/evaluation";
import { SkillEvaluation } from "@/components/skill-evaluation";

export default async function EvaluationPage() {
  // Vérifier l'authentification
  const isAuthenticated = await isUserAuthenticated();

  // Si pas de cookie d'authentification, rediriger vers login
  if (!isAuthenticated) {
    redirect("/login");
  }

  // Charger les données côté serveur
  const [userEvaluation, skillCategories, teams] = await Promise.all([
    getServerUserEvaluation(),
    getServerSkillCategories(),
    getServerTeams(),
  ]);

  return (
    <EvaluationClientWrapper
      userEvaluation={userEvaluation}
      teams={teams}
      skillCategories={skillCategories}
    >
      <div>
        {/* Skill Evaluation */}
        <SkillEvaluation
          categories={skillCategories}
          evaluations={userEvaluation?.evaluations || []}
        />
      </div>
    </EvaluationClientWrapper>
  );
}
