import type { JSX } from "react"
import { notFound } from "next/navigation"

import { getHomeworkSubmissionDetails } from "@/modules/homework/data-access"
import { HomeworkScanGradingView } from "@/modules/homework/components/homework-scan-grading-view"
import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"

export const dynamic = "force-dynamic"

export default async function HomeworkScanGradingPage({
  params,
}: {
  params: Promise<{ submissionId: string }>
}): Promise<JSX.Element> {
  const { submissionId } = await params
  await requirePermission(Permissions.HOMEWORK_GRADE)
  const submission = await getHomeworkSubmissionDetails(submissionId)

  if (!submission) return notFound()

  return (
    <div className="flex h-full flex-col space-y-4 p-6">
      <HomeworkScanGradingView
        submissionId={submission.id}
        studentName={submission.studentName}
        assignmentTitle={submission.assignmentTitle}
        submittedAt={submission.submittedAt}
        status={submission.status}
        totalScore={submission.totalScore}
        answers={submission.answers}
        prevSubmissionId={submission.prevSubmissionId}
        nextSubmissionId={submission.nextSubmissionId}
      />
    </div>
  )
}
