import type { JSX } from "react"
import { getTranslations } from "next-intl/server"

import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
import { getGrades, getStaffOptions, getSubjectOptions } from "@/modules/school/data-access"
import { ElectiveCourseForm } from "@/modules/elective/components/elective-course-form"

export const dynamic = "force-dynamic"

export default async function TeacherCreateElectiveCoursePage(): Promise<JSX.Element> {
  const t = await getTranslations("elective")
  await requirePermission(Permissions.ELECTIVE_MANAGE)

  const [subjects, grades, teachers] = await Promise.all([
    getSubjectOptions(),
    getGrades(),
    getStaffOptions(),
  ])

  return (
    <div className="flex h-full flex-col space-y-8 p-8">
      <div>
        <h2 className="text-2xl font-bold tracking-tight">{t("title.create")}</h2>
        <p className="text-muted-foreground">{t("description.create")}</p>
      </div>
      <ElectiveCourseForm
        mode="create"
        subjects={subjects}
        grades={grades.map((g) => ({ id: g.id, name: g.name }))}
        teachers={teachers.map((teacher) => ({ id: teacher.id, name: teacher.name }))}
        backHref="/teacher/elective"
      />
    </div>
  )
}
