import AppBreadcrumb from "@/components/generic/Breadcrumb/AppBreadcrumb"; import { useParams, useNavigate } from "react-router-dom"; import { House, Timer, CheckCircle2, Check, CheckCheck, ClipboardList, Hourglass, Sparkles, } from "lucide-react"; import { cn } from "@/lib/utils"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Progress } from "@/components/ui/progress"; import { Skeleton } from "@/components/ui/skeleton"; import { motion } from "framer-motion"; import { useEffect, useState } from "react"; import { useLibrary } from "@/contexts/ClientLibraryContext"; import { useClientTiers } from "@/contexts/ClientTiersProvider"; import { PageMeta } from "@/contexts/MetadataContext"; import UnitUpsellModal from "@/modules/client/components/UnitUpsellModal"; import { TYPE_DEFS } from "@/modules/admin/components/courses/completionRequirementTypes"; // ─── Helpers ────────────────────────────────────────────────────────────────── function formatDuration(seconds = 0) { if (!seconds) return null; const h = Math.floor(seconds / 3600); const m = Math.floor((seconds % 3600) / 60); if (h > 0) return `${h}hr ${m}min`; return `${m}min`; } // A unit under 5 lessons is assumed still being built out — nudge learners // that more is coming rather than let it read as a thin/finished unit. const ESTABLISHED_LESSON_COUNT = 5; const GrowingUnitNote = () => (
This unit is constantly improving — more lessons will be added soon.
); // ─── Lessons roadmap (single unit — lessons in order + trailing quiz row) ───── const LessonsRoadmap = ({ unitDetail, currentLessonId, onLessonClick, onContinue, onQuizClick }) => { const lessons = unitDetail.lessons ?? []; const quiz = unitDetail.quiz ?? null; return (
{lessons.map((lesson, index) => { const completed = lesson.status === "completed"; const isCurrent = lesson.lesson_id === currentLessonId; return ( onLessonClick(lesson)} >
{completed ? : index + 1}
{lesson.title} {formatDuration(lesson.duration_seconds) ?? "—"} {completed && " · Completed"} {isCurrent && !completed && " · In progress"}
{isCurrent && !completed && ( )}
); })} {quiz && (
onQuizClick()} >
{quiz.has_passed ? : } {quiz.title || "Quiz"}
{quiz.has_passed ? "Passed" : "Quiz"}
)}
); }; // ─── Unit Details ─────────────────────────────────────────────────────────── const UnitDetails = () => { const { uuid } = useParams(); const navigate = useNavigate(); const { getUnitDetail, unitDetail, unitDetailLoading, unitBlocked, unitBlockedInfo, resetUnitDetail } = useLibrary(); const { tierMap, getTierCategories } = useClientTiers(); const [upsellOpen, setUpsellOpen] = useState(false); // Locked units never get unitDetail (403'd) — fall back to the trimmed // shell info so the header still renders title/description/duration. const displayUnit = unitDetail ?? unitBlockedInfo?.item; const contentNotReady = !displayUnit?.duration_seconds; useEffect(() => { getTierCategories(); getUnitDetail(uuid); return () => resetUnitDetail(); // eslint-disable-next-line react-hooks/exhaustive-deps }, [uuid]); const items = [ { label: "Home", icon: , to: `/dashboard` }, { label: "Units", to: `/units` }, { label: displayUnit?.title ?? "Unit" }, ]; if (unitDetailLoading) { return (
); } const lessons = unitDetail?.lessons ?? []; const completedCount = lessons.filter((l) => l.status === "completed").length; const currentLesson = lessons.find((l) => l.status !== "completed") ?? null; const progressPct = lessons.length > 0 ? Math.round((completedCount / lessons.length) * 100) : 0; // Locked unit's own lessons/quiz — titles/durations only, a preview outline // that mirrors the unlocked layout but every row opens the upsell modal. const blockedLessons = unitBlockedInfo?.item?.lessons ?? []; const blockedQuiz = unitBlockedInfo?.item?.quiz ?? null; // Units always complete by passing their quiz now (registry.js hard-overrides // this regardless of what's actually configured) — reflect that here too. const requirementDef = TYPE_DEFS.pass_quiz; const RequirementIcon = requirementDef?.icon; const handleLessonClick = (lesson) => { navigate(`/lessons/${lesson.uuid}`); }; const handleContinue = (lesson) => { navigate(`/units/${uuid}/read`, { state: { lessonId: lesson.lesson_id } }); }; const handleQuizClick = () => { navigate(`/units/${uuid}/read`, { state: { quizId: true } }); }; return (
Unit

{displayUnit?.title ?? "Unit"}

{displayUnit?.description ?? ""}

{contentNotReady ? (
This unit is currently being prepared. Please check back later.
) : unitBlocked ? ( <>
{blockedLessons.length} {blockedLessons.length === 1 ? "lesson" : "lessons"} · {formatDuration(displayUnit.duration_seconds) ?? "—"} total

Lessons in this unit

setUpsellOpen(true)} onContinue={() => setUpsellOpen(true)} onQuizClick={() => setUpsellOpen(true)} /> {blockedLessons.length > 0 && blockedLessons.length < ESTABLISHED_LESSON_COUNT && }
) : ( <>
{lessons.length} {lessons.length === 1 ? "lesson" : "lessons"} · {formatDuration(unitDetail.duration_seconds) ?? "—"} total · {completedCount} of {lessons.length} complete {requirementDef && ( <> · {RequirementIcon && } {requirementDef.label} )}
{unitDetail.is_completed && (
Success — you've completed this unit.
)}

Lessons in this unit

{lessons.length > 0 && lessons.length < ESTABLISHED_LESSON_COUNT && }
)}
); }; export default UnitDetails;