import React, { useState, useEffect } from 'react'; import { Tag } from 'primereact/tag'; import { Button } from 'primereact/button'; import { Sidebar } from 'primereact/sidebar'; import Image from 'next/image'; import { useImageProxy } from '@/hooks/useImageProxy'; const CourseSidebar = ({ lessons, activeIndex, onLessonSelect, completedLessons, isMobileView, onClose, sidebarVisible: parentSidebarVisible, setSidebarVisible, hideToggleButton = false, }) => { const { returnImageProxy } = useImageProxy(); const [visible, setVisible] = useState(true); // Sync with parent state if provided useEffect(() => { if (typeof parentSidebarVisible !== 'undefined') { setVisible(parentSidebarVisible); } }, [parentSidebarVisible]); const handleToggle = () => { const newState = !visible; setVisible(newState); if (setSidebarVisible) { setSidebarVisible(newState); } }; const LessonItem = ({ lesson, index }) => (
  • onLessonSelect(index)} >
    {lesson.image && (
    {`Lesson
    )}
    Lesson {index + 1} {completedLessons.includes(lesson.id) && ( )}

    {lesson.title}

  • ); // Sidebar content component for reuse const SidebarContent = () => (

    Course Lessons

    {visible && !hideToggleButton && !isMobileView && (
    ); // Global toggle button container - only shown if hideToggleButton is false const SidebarToggle = () => { if (visible || hideToggleButton || isMobileView) return null; return (
    ); }; // Mobile content tab const MobileLessonsTab = () => (

    Course Lessons

    ); return ( <> {/* Unified button approach for desktop - only if not hidden */} {!hideToggleButton && } {/* Mobile view - direct content instead of sidebar */} {isMobileView && visible && ( )} {/* Desktop sidebar */} {!isMobileView && (
    )} ); }; export default CourseSidebar;