import { redirect } from "next/navigation";
import { AuthService } from "@/services";
import { SkillsService, TeamsService } from "@/services";
import { evaluationService } from "@/services/evaluation-service";
import { EvaluationClientWrapper } from "@/components/evaluation";
import { SkillEvaluation } from "@/components/skill-evaluation";

export default async function EvaluationPage() {
  // Charger les données côté serveur
  const userUuid = await AuthService.getUserUuidFromCookie();

  if (!userUuid) {
    redirect("/login");
  }

  const [userEvaluation, skillCategories, teams] = await Promise.all([
    evaluationService.getServerUserEvaluation(userUuid!),
    SkillsService.getSkillCategories(),
    TeamsService.getTeams(),
  ]);

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