import { BadgeCheck, ChevronRight, Clock, ImageOff, Star, Users, Zap } from "lucide-react"; import { useState } from "react"; import { Link } from "react-router"; import { TiltCard } from "@/components/ui/motion"; import { useTranslation } from "@/hooks/useTranslation"; import { formatNumber } from "@/lib/format"; import { youTubeThumbnailFallback } from "@/lib/youtube-url"; interface CourseCardProps { readonly course: { readonly id: number; readonly slug: string; readonly titleEn: string; readonly titleAr: string; readonly shortDescEn: string | null; readonly shortDescAr: string | null; readonly thumbnail: string | null; readonly level: string; readonly isPremium: boolean; readonly price: string; readonly originalPrice: string | null; readonly durationHours: number; readonly rating: string; readonly reviewCount: number; readonly studentCount: number; readonly categoryName?: string | null; readonly categoryNameAr?: string | null; }; } const levelColors: Record = { beginner: { bg: "rgba(16,185,129,0.12)", text: "#10b981", label: "Beginner", labelAr: "مبتدئ" }, intermediate: { bg: "rgba(245,158,11,0.12)", text: "#f59e0b", label: "Intermediate", labelAr: "متوسط" }, advanced: { bg: "rgba(239,68,68,0.12)", text: "#ef4444", label: "Advanced", labelAr: "متقدم" }, }; function CourseCardBadges({ course, lang, discount }: { readonly course: { readonly isPremium: boolean }; readonly lang: "ar" | "en"; readonly discount: number }) { return (
{course.isPremium ? ( Premium ) : ( {lang === "ar" ? "مجاني" : "Free"} )} {discount > 0 && ( -{discount}% )}
); } function ThumbnailFallback({ title }: { readonly title: string }) { return (

{title}

); } function CourseCardPrice({ coursePrice, originalPrice, lang }: { readonly coursePrice: number; readonly originalPrice: number; readonly lang: "ar" | "en" }) { if (coursePrice === 0) { return ( {lang === "ar" ? "مجاناً" : "Free"} ); } return (
{formatNumber(coursePrice)} {lang === "ar" ? "ج.م" : "EGP"} {originalPrice > coursePrice && ( {formatNumber(originalPrice)} )}
); } function CourseCardStats({ lang, rating, reviewCount, studentCount }: { readonly lang: "ar" | "en"; readonly rating: string; readonly reviewCount: number; readonly studentCount: number }) { return (
{Number.parseFloat(rating).toFixed(1)} ({reviewCount})
{studentCount >= 1000 ? `${(studentCount / 1000).toFixed(1)}k` : formatNumber(studentCount)} {lang === "ar" ? " طالب" : " students"}
{/* Brand Kit §7 proof system — the ONE green check badge, identical language on course cards, reviews and certificates. Truthful platform-wide: completion of every course awards a verifiable certificate (QR /verify). */}
{lang === "ar" ? "شهادة موثقة" : "Certified"}
); } export default function CourseCard({ course }: CourseCardProps) { const { lang } = useTranslation(); const title = lang === "ar" && course.titleAr ? course.titleAr : course.titleEn; const shortDesc = lang === "ar" && course.shortDescAr ? course.shortDescAr : course.shortDescEn; const categoryLabel = lang === "ar" && course.categoryNameAr ? course.categoryNameAr : course.categoryName; const coursePrice = Number.parseFloat(course.price || "0"); const originalPrice = course.originalPrice ? Number.parseFloat(course.originalPrice) : 0; const discount = originalPrice > coursePrice && originalPrice > 0 ? Math.round(((originalPrice - coursePrice) / originalPrice) * 100) : 0; const lvl = levelColors[course.level] || levelColors.beginner; const dir = lang === "ar" ? "rtl" : "ltr"; const [thumbSrc, setThumbSrc] = useState(course.thumbnail); const [thumbError, setThumbError] = useState(false); // Adjust state during render when the prop changes (React docs pattern) — // the playlist sync updates the cover server-side while the card is mounted. const [prevThumbnail, setPrevThumbnail] = useState(course.thumbnail); if (prevThumbnail !== course.thumbnail) { setPrevThumbnail(course.thumbnail); setThumbSrc(course.thumbnail); setThumbError(false); } const onThumbError = () => { const next = youTubeThumbnailFallback(thumbSrc); if (next) { setThumbSrc(next); return; } setThumbError(true); }; return (
{/* ── Thumbnail ── */}
{thumbError ? ( ) : ( {title} )} {/* Gradient overlay */}
{/* Top badges row */} {/* Duration — bottom right */}
{course.durationHours}{lang === "ar" ? "س" : "h"}
{/* ── Body ── */}
{/* Category + Level */}
{categoryLabel || "Engineering"} {lang === "ar" ? lvl.labelAr : lvl.label}
{/* Title */}

{title}

{/* Short description */} {shortDesc && (

{shortDesc}

)} {/* ── Stats row ── */}
{/* ── Separator ── */}
{/* ── Price + CTA ── */}
{/* Animated CTA arrow */}
{/* Shimmer line on hover */}
{/* Premium shine sweep effect */}
); }