"use client"; import { useState, useEffect } from "react"; import { Link } from "@/i18n/navigation"; import { Section } from "./Section"; import { CURRICULUM_CONFIG } from "@/config/course"; import { canWatchLesson, isFreeTrial } from "@/app/lib/course-payment"; import { useAuthAndVip } from "@/app/lib/useAuthAndVip"; import { isBookmarked, toggleBookmark, getBookmarks, getCompletedLessons } from "@/app/lib/learning"; export function CurriculumSection() { const { vip } = useAuthAndVip(); const [expanded, setExpanded] = useState>(() => Object.fromEntries(CURRICULUM_CONFIG.modules.map((_, i) => [i, i === 0])) ); const [search, setSearch] = useState(""); const [bookmarks, setBookmarks] = useState>(new Set()); const [completed, setCompleted] = useState>(new Set()); useEffect(() => { setBookmarks(getBookmarks()); setCompleted(getCompletedLessons()); const onB = () => setBookmarks(getBookmarks()); const onP = () => setCompleted(getCompletedLessons()); window.addEventListener("learning:bookmarks", onB); window.addEventListener("learning:progress", onP); return () => { window.removeEventListener("learning:bookmarks", onB); window.removeEventListener("learning:progress", onP); }; }, []); const toggle = (i: number) => { setExpanded((prev) => ({ ...prev, [i]: !prev[i] })); }; const allLessons = CURRICULUM_CONFIG.modules.flatMap((m, mi) => m.lessons.map((l, li) => ({ moduleIndex: mi, lessonIndex: li, ...l, moduleTitle: m.title })) ); const filtered = search.trim() ? allLessons.filter( (l) => l.name.toLowerCase().includes(search.toLowerCase()) || l.moduleTitle.toLowerCase().includes(search.toLowerCase()) ) : allLessons; const filteredByModule = CURRICULUM_CONFIG.modules .map((m, mi) => ({ ...m, lessons: filtered.filter((l) => l.moduleIndex === mi), })) .filter((m) => m.lessons.length > 0); return (

{CURRICULUM_CONFIG.title}

{CURRICULUM_CONFIG.subtitle}

setSearch(e.target.value)} className="w-full rounded-full border border-[var(--border)] bg-[var(--background)] px-4 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-[var(--accent)]" />
{filteredByModule.map((c) => { const moduleIndex = CURRICULUM_CONFIG.modules.findIndex((m) => m.title === c.title); const isOpen = expanded[moduleIndex] ?? true; return (
{isOpen && (
    {c.lessons.map((l) => { const unlocked = canWatchLesson(l.moduleIndex, l.lessonIndex, vip); const key = `${l.moduleIndex}-${l.lessonIndex}`; const bookmarked = isBookmarked(l.moduleIndex, l.lessonIndex); const isCompleted = completed.has(key); return (
  • {l.name} {isFreeTrial(l.moduleIndex, l.lessonIndex) && ( 试看 )} {isCompleted && ( )} {!unlocked && ( 🔒 )} {l.duration}
  • ); })}
)}
); })}
); }