import { UserX } from "lucide-react"

import { getStudentClasses } from "@/modules/classes/data-access"
import { getCurrentStudentUser } from "@/modules/users/data-access"
import { StudentCoursesView } from "@/modules/student/components/student-courses-view"
import { EmptyState } from "@/shared/components/ui/empty-state"

export const dynamic = "force-dynamic"

export default async function StudentCoursesPage() {
  const student = await getCurrentStudentUser()
  if (!student) {
    return (
      <div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
        <div>
          <h2 className="text-2xl font-bold tracking-tight">Courses</h2>
          <p className="text-muted-foreground">Your enrolled classes.</p>
        </div>
        <EmptyState
          title="No user found"
          description="Create a student user to see courses."
          icon={UserX}
        />
      </div>
    )
  }

  const classes = await getStudentClasses(student.id)

  return (
    <div className="flex h-full flex-col space-y-8 p-8">
      <div>
        <h2 className="text-2xl font-bold tracking-tight">Courses</h2>
        <p className="text-muted-foreground">Your enrolled classes.</p>
      </div>
      <StudentCoursesView classes={classes} />
    </div>
  )
}

