import { useParams, Link } from "react-router-dom"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Progress } from "@/components/ui/progress"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { Button } from "@/components/ui/button"; import { useCourse, useChapters, useGrades, useCourseCompletion } from "@/hooks/queries"; import { ArrowLeft, BookOpen, Lock, ChevronRight, Play, CheckCircle2, Trophy } from "lucide-react"; export default function StudentCourseDetail() { const { id } = useParams(); const courseId = Number(id); const { data: course, isLoading: lc } = useCourse(courseId); const { data: chapters = [], isLoading: lch } = useChapters(courseId); const { data: gradesData, isLoading: lg } = useGrades({ course_id: courseId }); const { data: completion } = useCourseCompletion(courseId); const gradeRecords = gradesData ?? []; if (lc || lch || lg) return
; if (!course) return
Course not found.
; const sortedChapters = [...chapters].sort((a, b) => a.sequence - b.sequence); const completedChapters = completion?.chapters_completed ?? 0; const progress = completion?.progress_percent ?? (chapters.length > 0 ? Math.round((completedChapters / chapters.length) * 100) : 0); const isCompleted = completion?.status === "completed"; const postTestAvailable = completion?.post_test_available ?? false; return (

{course.title}

{course.code} · {chapters.length} chapters

{isCompleted && (

Course Completed!

You've finished all {chapters.length} chapters.

{postTestAvailable && ( )}
)}
Overall Progress {progress}%

{completedChapters} of {chapters.length} chapters completed

Chapters ({chapters.length}) Grades ({gradeRecords.length}) About {sortedChapters.length === 0 ? (

No chapters available yet.

) : sortedChapters.map((ch, idx) => (
{idx + 1}

{ch.name}

{!ch.is_unlocked && }

{ch.material_count} materials {ch.description ? ` · ${ch.description.slice(0, 60)}${ch.description.length > 60 ? "..." : ""}` : ""}

{ch.is_unlocked ? ( Open ) : ( Locked )}
))}
{gradeRecords.length === 0 ? (

No grades yet for this course.

) : gradeRecords.map(g => (

{g.assignment_title}

{g.date}

{g.grade}/{g.max_grade}
))}
About this Course

{course.description || "No description available."}

Enrolled Students: {course.enrolled}
Max Capacity: {course.max_capacity}
); }