import Link from "next/link"; import { notFound } from "next/navigation"; import { db } from "@/lib/prisma"; import { requireUser } from "@/lib/auth/requireUser"; function getText(value: unknown): string { if (!value) return ""; if (typeof value === "string") return value; if (typeof value === "object") { const record = value as Record; if (typeof record.en === "string") return record.en; if (typeof record.es === "string") return record.es; } return ""; } const levelLabel = (level: string) => { if (level === "BEGINNER") return "Beginner"; if (level === "INTERMEDIATE") return "Intermediate"; if (level === "ADVANCED") return "Advanced"; return level; }; type PageProps = { params: Promise<{ slug: string }>; }; export default async function CourseDetailPage({ params }: PageProps) { const { slug } = await params; const course = await db.course.findFirst({ where: { slug, status: "PUBLISHED" }, include: { author: { select: { fullName: true } }, modules: { orderBy: { orderIndex: "asc" }, include: { lessons: { orderBy: { orderIndex: "asc" }, select: { id: true, title: true, estimatedDuration: true }, }, }, }, _count: { select: { enrollments: true } }, }, }); if (!course) notFound(); const user = await requireUser(); const isAuthed = Boolean(user?.id); const title = getText(course.title) || "Untitled course"; const summary = getText(course.description) || ""; const lessons = course.modules.flatMap((m) => m.lessons.map((l) => ({ id: l.id, title: getText(l.title) || "Untitled lesson", minutes: Math.ceil((l.estimatedDuration ?? 0) / 60), })), ); const lessonsCount = lessons.length; const redirect = `/courses/${course.slug}/learn`; const loginUrl = `/auth/login?redirectTo=${encodeURIComponent(redirect)}`; const learningOutcomes = [ "Understand key legal vocabulary in context", "Apply contract and case analysis patterns", "Improve professional written legal communication", ]; return (
{"<-"} Back to Courses
{levelLabel(course.level)} {course.status.toLowerCase()} {lessonsCount} lessons

{title}

{summary}

Students

{course._count.enrollments.toLocaleString()}

Lessons

{lessonsCount}

Instructor

{course.author.fullName || "ACVE Team"}

Course structure preview

{lessons.slice(0, 5).map((lesson, index) => (
Lesson {index + 1}: {lesson.title} {lesson.minutes} min
))} {lessons.length === 0 && (

No lessons yet. Check back soon.

)}
); }