import type { JSX } from "react"
import { TeacherDashboardView } from "@/modules/dashboard/components/teacher-dashboard/teacher-dashboard-view"
import { getClassSchedule, getTeacherClasses, getTeacherIdForMutations } from "@/modules/classes/data-access"
import { getHomeworkAssignments, getHomeworkSubmissions, getTeacherGradeTrends } from "@/modules/homework/data-access"
import { getUserBasicInfo } from "@/modules/users/data-access"
import { getAuthContext } from "@/shared/lib/auth-guard"

export const dynamic = "force-dynamic"

export default async function TeacherDashboardPage(): Promise<JSX.Element> {
  await getAuthContext()
  const teacherId = await getTeacherIdForMutations()

  const [classes, schedule, assignments, submissions, teacherProfile, gradeTrends] = await Promise.all([
    getTeacherClasses({ teacherId }),
    getClassSchedule({ teacherId }),
    getHomeworkAssignments({ creatorId: teacherId }),
    getHomeworkSubmissions({ creatorId: teacherId }),
    getUserBasicInfo(teacherId),
    getTeacherGradeTrends(teacherId),
  ])

  return (
    <TeacherDashboardView
      data={{
        classes,
        schedule,
        assignments,
        submissions,
        teacherName: teacherProfile?.name ?? "Teacher",
        gradeTrends,
      }}
    />
  )
}
