import { Stethoscope } from "lucide-react"
import { getTranslations } from "next-intl/server"

import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
import { getStudentMasterySummary } from "@/modules/diagnostic/data-access"
import { getDiagnosticReports } from "@/modules/diagnostic/data-access-reports"
import { StudentDiagnosticView } from "@/modules/diagnostic/components/student-diagnostic-view"

export const dynamic = "force-dynamic"

export default async function StudentDiagnosticPage() {
  const ctx = await requirePermission(Permissions.DIAGNOSTIC_READ)
  const t = await getTranslations("student")

  const [summary, reportsResult] = await Promise.all([
    getStudentMasterySummary(ctx.userId),
    // v4-P1-3: 学生仅可见已发布报告，避免草稿泄露
    getDiagnosticReports(
      { studentId: ctx.userId, status: "published" },
      ctx.dataScope,
    ),
  ])
  const reports = reportsResult.reports

  return (
    <div className="space-y-8">
      <div>
        <h2 className="flex items-center gap-2 text-2xl font-bold tracking-tight">
          <Stethoscope className="h-6 w-6" />
          {t("diagnostic.title")}
        </h2>
        <p className="text-muted-foreground">
          {t("diagnostic.description")}
        </p>
      </div>
      <StudentDiagnosticView summary={summary} reports={reports} role="student" />
    </div>
  )
}
