import type { Metadata } from "next"
import type { JSX } from "react"
import { getTranslations } from "next-intl/server"

import { StudentDashboard } from "@/modules/dashboard/components/student-dashboard/student-dashboard-view"
import { getStudentDashboardAction } from "@/modules/dashboard/actions"
import { EmptyState } from "@/shared/components/ui/empty-state"
import { UserX } from "lucide-react"

export const dynamic = "force-dynamic"

export async function generateMetadata(): Promise<Metadata> {
  const t = await getTranslations("dashboard")
  return {
    title: t("title.student"),
    description: t("description.student"),
  }
}

export default async function StudentDashboardPage(): Promise<JSX.Element> {
  const t = await getTranslations("dashboard")
  const { student, dashboardProps } = await getStudentDashboardAction()

  if (!student || !dashboardProps) {
    return (
      <EmptyState
        title={t("empty.noStudent")}
        description={t("empty.noStudentDesc")}
        icon={UserX}
        className="border-none shadow-none h-auto"
      />
    )
  }

  return (
    <div className="space-y-8">
      <StudentDashboard
        studentName={student.name}
        {...dashboardProps}
      />
    </div>
  )
}
