import Link from "next/link"; import type { Prisma } from "@prisma/client"; import ProgressBar from "@/components/ProgressBar"; import { Card, CardContent, CardHeader, CardTitle, CardDescription, CardFooter } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; type PublicCourseCardCourse = Prisma.CourseGetPayload<{ include: { author: { select: { fullName: true; }; }; modules: { select: { _count: { select: { lessons: true; }; }; }; }; _count: { select: { enrollments: true; }; }; }; }>; type CourseCardProps = { course: PublicCourseCardCourse; progress?: number; }; const levelBadgeClass = (level: PublicCourseCardCourse["level"]) => { if (level === "BEGINNER") return "bg-emerald-100 text-emerald-900 border border-emerald-200"; if (level === "INTERMEDIATE") return "bg-sky-100 text-sky-900 border border-sky-200"; return "bg-violet-100 text-violet-900 border border-violet-200"; }; const levelLabel = (level: PublicCourseCardCourse["level"]) => { if (level === "BEGINNER") return "Beginner"; if (level === "INTERMEDIATE") return "Intermediate"; return "Advanced"; }; const 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 ""; }; export default function CourseCard({ course, progress = 0 }: CourseCardProps) { const lessonsCount = course.modules.reduce((total, module) => total + module._count.lessons, 0); const title = getText(course.title) || "Untitled course"; const summary = getText(course.description) || "Course details will be published soon."; const instructor = course.author.fullName || "ACVE Team"; return (
{levelLabel(course.level)} {course.status.toLowerCase()}
{lessonsCount} lessons
{title} {summary}
{progress > 0 ? (
) : null}
{course._count.enrollments.toLocaleString()} enrolled {lessonsCount} lessons
By {instructor}
View Course {">"}
); }