import { auth } from "@/auth"; import { db } from "@/lib/db"; import { setRequestLocale } from "next-intl/server"; import Link from "next/link"; import { EnrollPathButton } from "./EnrollPathButton"; export const dynamic = "force-dynamic"; function getLocaleText(obj: any, locale: string, field: string) { if (locale === "en") return obj[`${field}En`] || obj[`${field}Fr`]; if (locale === "es") return obj[`${field}Es`] || obj[`${field}Fr`]; return obj[`${field}Fr`]; } const levelColors: Record = { BEGINNER: "#4ade80", INTERMEDIATE: "#fbbf24", ADVANCED: "#f87171", }; export default async function PathsPage({ params, }: { params: Promise<{ locale: string }>; }) { const { locale } = await params; setRequestLocale(locale); const session = await auth(); const userId = (session?.user as any)?.id as string | undefined; const paths = await db.learningPath.findMany({ where: { published: true }, orderBy: { order: "asc" }, include: { courses: { include: { course: { include: { modules: { include: { lessons: { select: { id: true } } } } }, }, }, orderBy: { order: "asc" }, }, _count: { select: { enrollments: true } }, }, }); // Check which paths the user is enrolled in const enrolledPathIds = userId ? new Set( (await db.learningPathEnrollment.findMany({ where: { userId }, select: { learningPathId: true } })).map( (e) => e.learningPathId ) ) : new Set(); return (

Parcours de formation

Des programmes complets pour maîtriser la GRC et l'application OwlCub.

{paths.length === 0 ? (

Aucun parcours disponible pour l'instant.

) : (
{paths.map((path) => { const title = getLocaleText(path, locale, "title"); const desc = getLocaleText(path, locale, "desc"); const totalLessons = path.courses.reduce((sum, lpc) => sum + lpc.course.modules.reduce((s, m) => s + m.lessons.length, 0), 0); const isEnrolled = enrolledPathIds.has(path.id); return (

{title}

{isEnrolled && ( Inscrit )}

{desc}

{/* Course list */}
{path.courses.map((lpc, i) => { const courseTitle = getLocaleText(lpc.course, locale, "title"); const lessonCount = lpc.course.modules.reduce((s, m) => s + m.lessons.length, 0); return (
{i + 1} {courseTitle} · {lessonCount} leçon{lessonCount !== 1 ? "s" : ""} {lpc.course.level}
); })}
📚 {path.courses.length} formation{path.courses.length !== 1 ? "s" : ""} 🎬 {totalLessons} leçons 👥 {path._count.enrollments} inscrits
{isEnrolled ? ( Continuer → ) : ( )} Voir le détail
); })}
)}
); }