import type { Metadata } from "next"
import type { JSX } from "react"

import { getAdminClasses } from "@/modules/classes/data-access"
import { getAcademicYears, getStaffOptions } from "@/modules/school/data-access"
import { getSubjectOptions } from "@/modules/course-plans/data-access"
import { CoursePlanForm } from "@/modules/course-plans/components/course-plan-form"

export const metadata: Metadata = {
  title: "新建课程计划 - Next_Edu",
  description: "创建新的课程教学计划",
}

export const dynamic = "force-dynamic"

export default async function CreateCoursePlanPage(): Promise<JSX.Element> {
  const [classes, subjects, teachers, academicYears] = await Promise.all([
    getAdminClasses(),
    getSubjectOptions(),
    getStaffOptions(),
    getAcademicYears(),
  ])

  return (
    <div className="flex h-full flex-col space-y-8 p-8">
      <div>
        <h2 className="text-2xl font-bold tracking-tight">新建课程计划</h2>
        <p className="text-muted-foreground">创建新的课程教学计划。</p>
      </div>
      <CoursePlanForm
        mode="create"
        classes={classes.map((c) => ({ id: c.id, name: c.name }))}
        subjects={subjects}
        teachers={teachers.map((t) => ({ id: t.id, name: t.name }))}
        academicYears={academicYears.map((y) => ({ id: y.id, name: y.name }))}
        backHref="/admin/course-plans"
      />
    </div>
  )
}
