import { XMarkIcon, BookOpenIcon } from "@heroicons/react/24/outline"; import { ChevronDownIcon, ClockIcon, PlayCircleIcon, } from "@heroicons/react/24/outline"; import { ChevronLeftIcon, ChevronRightIcon } from "@heroicons/react/24/outline"; import React, { useState, useRef } from "react"; import { motion, AnimatePresence } from "framer-motion"; import { SectionDto } from "@nice/common"; interface CourseSyllabusProps { sections: SectionDto[]; onLectureClick?: (lectureId: string) => void; isOpen: boolean; onToggle: () => void; } export const CourseSyllabus: React.FC = ({ sections, onLectureClick, isOpen, onToggle, }) => { const [expandedSections, setExpandedSections] = useState([]); const sectionRefs = useRef<{ [key: string]: HTMLDivElement | null }>({}); const toggleSection = (sectionId: string) => { setExpandedSections((prev) => prev.includes(sectionId) ? prev.filter((id) => id !== sectionId) : [...prev, sectionId] ); // 平滑滚动到选中的章节 setTimeout(() => { sectionRefs.current[sectionId]?.scrollIntoView({ behavior: "smooth", block: "start", }); }, 100); }; return ( {/* 收起时显示的展开按钮 */} {!isOpen && ( )} {/* 展开的课程大纲 */} {isOpen && ( {/* 标题栏 */}

课程大纲

{/* 课程大纲内容 */}
{/* 原有的 sections mapping 内容 */} {sections.map((section) => ( (sectionRefs.current[section.id] = el) } initial={{ opacity: 0, y: 20 }} animate={{ opacity: 1, y: 0 }} transition={{ duration: 0.3 }} className="border rounded-lg overflow-hidden bg-white shadow-sm hover:shadow-md transition-shadow"> {expandedSections.includes( section.id ) && ( {section.lectures.map( (lecture) => ( onLectureClick?.( lecture.id ) }>

{ lecture.title }

{lecture.description && (

{ lecture.description }

)}
{ lecture.duration } 分钟
) )}
)}
))}
)}
); };