import type { Metadata } from "next" import Link from "next/link" import { BookOpen, PenTool, Library, ArrowRight, UserX } from "lucide-react" import { getTranslations } from "next-intl/server" import { getStudentClasses } from "@/modules/classes/data-access" import { getStudentHomeworkAssignments } from "@/modules/homework/data-access-student" import { getCurrentStudentUser } from "@/modules/users/data-access" import { getTextbooks } from "@/modules/textbooks/data-access" import { requirePermission } from "@/shared/lib/auth-guard" import { Permissions } from "@/shared/types/permissions" import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card" import { EmptyState } from "@/shared/components/ui/empty-state" export const dynamic = "force-dynamic" export async function generateMetadata(): Promise { const t = await getTranslations("classes") return { title: `${t("metadata.studentLearning")} - Next_Edu`, description: t("metadata.studentLearning"), } } export default async function StudentLearningPage() { const t = await getTranslations("student") await requirePermission(Permissions.CLASS_READ) const student = await getCurrentStudentUser() if (!student) { return (
) } const [classes, assignments, textbooks] = await Promise.all([ getStudentClasses(student.id), getStudentHomeworkAssignments(student.id), getTextbooks(), ]) const now = new Date() const pendingCount = assignments.filter((a) => a.progressStatus !== "submitted" && a.progressStatus !== "graded").length const dueSoonCount = assignments.filter((a) => { if (a.progressStatus === "submitted" || a.progressStatus === "graded") return false if (!a.dueAt) return false const due = new Date(a.dueAt) const in7Days = new Date(now) in7Days.setDate(in7Days.getDate() + 7) return due >= now && due <= in7Days }).length const cards = [ { title: t("learning.courses"), description: t("learning.coursesDesc"), icon: BookOpen, href: "/student/learning/courses", stat: t("learning.enrolled", { count: classes.length }), }, { title: t("learning.assignments"), description: t("learning.assignmentsDesc"), icon: PenTool, href: "/student/learning/assignments", stat: t("learning.pending", { count: pendingCount }) + (dueSoonCount > 0 ? t("learning.dueSoon", { count: dueSoonCount }) : ""), }, { title: t("learning.textbooks"), description: t("learning.textbooksDesc"), icon: Library, href: "/student/learning/textbooks", stat: t("learning.available", { count: textbooks.length }), }, ] return (

{t("learning.title")}

{t("learning.description")}

{cards.map((c) => ( {c.title}

{c.description}

{c.stat}
))}
) }