import { Navigate } from "react-router-dom";
import { useAuth } from "@/contexts/AuthContext";
import { ApplicantProfileView } from "@/components/applicant/profile";

/**
 * Hồ sơ người nộp đơn tại `/applicant/profile` (chỉ vai trò xem/ứng viên).
 */
export default function ApplicantProfilePage() {
  const { hasRole, loading, isAuthenticated } = useAuth();
  const isApplicant = hasRole("viewer");

  if (loading) {
    return null;
  }
  if (!isAuthenticated) {
    return <Navigate to="/login" replace />;
  }
  if (!isApplicant) {
    return <Navigate to="/dashboard" replace />;
  }

  return <ApplicantProfileView />;
}
