"use client"; import { useState, useEffect } from "react"; import { ChevronRight, ChevronDown, Circle } from "lucide-react"; import { useTranslation } from "react-i18next"; interface KnowledgePoint { id: string; name: string; type: string; } interface Module { id: string; name: string; order: number; knowledge_points: KnowledgePoint[]; pass_threshold: number; } interface ModuleTreeProps { modules: Module[]; masteryLevels: Record; currentModuleId: string; currentStage: string; } function masteryColor(mastery: number, threshold: number): string { if (mastery >= threshold) return "text-green-500"; if (mastery > 0) return "text-yellow-500"; return "text-[var(--muted-foreground)]"; } function ModuleNode({ module, masteryLevels, isCurrent, }: { module: Module; masteryLevels: Record; isCurrent: boolean; }) { const [expanded, setExpanded] = useState(isCurrent); useEffect(() => { if (isCurrent) setExpanded(true); }, [isCurrent]); const mastered = module.knowledge_points.filter( (kp) => (masteryLevels[kp.id] ?? 0) >= module.pass_threshold ).length; const total = module.knowledge_points.length; const passRate = total > 0 ? Math.round((mastered / total) * 100) : 0; return (
{expanded && (
{module.knowledge_points.map((kp) => { const mastery = masteryLevels[kp.id] ?? 0; return (
{kp.name}
); })}
)}
); } export default function ModuleTree({ modules, masteryLevels, currentModuleId, currentStage, }: ModuleTreeProps) { const { t } = useTranslation(); const sorted = [...modules].sort((a, b) => a.order - b.order); if (sorted.length === 0) { return (
{t("guidedLearning.noModulesLoaded")}
); } return (
{sorted.map((mod) => ( ))}
); }