import { getTranslations } from "next-intl/server"
import { requirePermission, getAuthContext } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
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() {
  await requirePermission(Permissions.ATTENDANCE_READ)
  const ctx = await getAuthContext()
  const t = await getTranslations("attendance")

  const summary = await getStudentAttendanceSummary(ctx.userId)

  if (!summary) {
    return (
      <div className="space-y-8">
        <div>
          <h2 className="text-2xl font-bold tracking-tight">{t("title.student")}</h2>
          <p className="text-muted-foreground">{t("description.student")}</p>
        </div>
        <EmptyState
          title={t("list.empty")}
          description={t("list.emptyDescription")}
          icon={UserX}
          className="border-none shadow-none"
        />
      </div>
    )
  }

  return (
    <div className="space-y-8">
      <div>
        <h2 className="text-2xl font-bold tracking-tight">{t("title.student")}</h2>
        <p className="text-muted-foreground">{t("description.student")}</p>
      </div>
      <StudentAttendanceView summary={summary} />
    </div>
  )
}
