import { getAuthContext } from "@/shared/lib/auth-guard"
import { getStudentGradeSummary } from "@/modules/grades/data-access"
import { StudentGradeSummary } from "@/modules/grades/components/student-grade-summary"
import { EmptyState } from "@/shared/components/ui/empty-state"
import { GraduationCap } from "lucide-react"

export const dynamic = "force-dynamic"

export default async function StudentGradesPage() {
  const ctx = await getAuthContext()

  const summary = await getStudentGradeSummary(ctx.userId)

  if (!summary) {
    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">My Grades</h2>
          <p className="text-muted-foreground">View your grade records.</p>
        </div>
        <EmptyState
          title="No user found"
          description="Unable to load your student profile."
          icon={GraduationCap}
          className="border-none shadow-none"
        />
      </div>
    )
  }

  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">My Grades</h2>
        <p className="text-muted-foreground">View your grade records.</p>
      </div>
      <StudentGradeSummary summary={summary} />
    </div>
  )
}
