import { Navigate } from "react-router-dom";
import AdminApprovedApplicationsList from "@/components/admin/ApprovedApplicationsList";
import { useAuth } from "@/contexts/AuthContext";

/**
 * Admin «Projects» hub: same application listing as the inbox, plus per-row full backup ZIP download.
 * Sidebar: Management → Projects (`/dashboard/projects`).
 */
export default function AdminProjectsPage() {
  const { hasRole, loading } = useAuth();
  if (loading) {
    return <div className="text-sm text-muted-foreground">Đang xác thực…</div>;
  }
  if (!hasRole("admin")) {
    return <Navigate to="/unauthorized" replace />;
  }

  return (
    <div className="space-y-4 animate-fade-in">
      <div>
        <h1 className="text-2xl font-semibold tracking-tight">Dự án &amp; sao lưu hồ sơ</h1>
        <p className="mt-1 max-w-3xl text-sm text-muted-foreground">
          Tải gói ZIP đầy đủ (PDF nộp, biểu mẫu, minh chứng, manifest) cho từng hồ sơ. Tên file:
          <span className="font-mono text-xs"> {"{username}_{applicationId}.zip"}</span> — username lấy từ email đăng
          nhập của tác giả (phần trước @) hoặc họ tên.
        </p>
      </div>
      <AdminApprovedApplicationsList
        showBackupDownloadColumn
        viewSubmittedReturnPath="/dashboard/projects"
        filterCardTitle="Lọc hồ sơ"
        resultsSectionTitle="Danh sách hồ sơ"
      />
    </div>
  );
}
