import type { JSX } from "react"
import { HomeworkAssignmentForm } from "@/modules/homework/components/homework-assignment-form"
import { getExams } from "@/modules/exams/data-access"
import { getTeacherClasses } from "@/modules/classes/data-access"
import { EmptyState } from "@/shared/components/ui/empty-state"
import { getAuthContext } from "@/shared/lib/auth-guard"
import { getTranslations } from "next-intl/server"
import { FileQuestion } from "lucide-react"

export const dynamic = "force-dynamic"

export default async function CreateHomeworkAssignmentPage(): Promise<JSX.Element> {
  const { dataScope } = await getAuthContext()
  const t = await getTranslations("examHomework")
  const [exams, classes] = await Promise.all([getExams({ scope: dataScope }), getTeacherClasses()])
  const options = exams.map((e) => ({ id: e.id, title: e.title }))

  return (
    <div className="flex h-full flex-col space-y-8 p-8">
      <div className="flex items-center justify-between">
        <div>
          <h1 className="text-2xl font-bold tracking-tight">{t("homework.form.createTitle")}</h1>
          <p className="text-muted-foreground">{t("homework.form.createDescription")}</p>
        </div>
      </div>

      {classes.length === 0 ? (
        <EmptyState
          title={t("homework.form.noClassesAvailable")}
          description={t("homework.form.noClassesDescription")}
          icon={FileQuestion}
          action={{ label: t("homework.form.goToClasses"), href: "/teacher/classes/my" }}
        />
      ) : (
        <HomeworkAssignmentForm exams={options} classes={classes} />
      )}
    </div>
  )
}
