import type { Metadata } from "next"
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 { getClassSubjects, getTeacherClasses } from "@/modules/classes/data-access"
import { ClassErrorBoundary } from "@/modules/classes/components/class-error-boundary"
import { MyClassesGrid } from "@/modules/classes/components/my-classes-grid"

export const dynamic = "force-dynamic"

export async function generateMetadata(): Promise<Metadata> {
  const t = await getTranslations("classes")
  return {
    title: `${t("metadata.myClasses")} - Next_Edu`,
    description: t("metadata.myClasses"),
  }
}

export default async function MyClassesPage(): Promise<JSX.Element> {
  await requirePermission(Permissions.CLASS_READ)
  const [classes, subjectOptions] = await Promise.all([getTeacherClasses(), getClassSubjects()])

  return (
    <div className="flex h-full flex-col space-y-4 p-8">
      <ClassErrorBoundary>
        <MyClassesGrid classes={classes} subjectOptions={subjectOptions} />
      </ClassErrorBoundary>
    </div>
  )
}
