import { getAuthContext } from "@/shared/lib/auth-guard"
import { getStudentAttendanceSummary } from "@/modules/attendance/data-access-stats"
import { StudentAttendanceView } from "@/modules/attendance/components/student-attendance-view"
import { EmptyState } from "@/shared/components/ui/empty-state"
import { UserX } from "lucide-react"

export const dynamic = "force-dynamic"

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

  const summary = await getStudentAttendanceSummary(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 Attendance</h2>
          <p className="text-muted-foreground">View your attendance records.</p>
        </div>
        <EmptyState
          title="No user found"
          description="Unable to load your student profile."
          icon={UserX}
          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 Attendance</h2>
        <p className="text-muted-foreground">View your attendance records and statistics.</p>
      </div>
      <StudentAttendanceView summary={summary} />
    </div>
  )
}
