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, }) => { 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 && (
    ); // Toggle button (used for both desktop and mobile) const ToggleButton = () => (
    ); // Desktop implementation with integrated toggle button if (!isMobileView) { return ( <> {/* Sidebar content */}
    {/* Detached toggle button when sidebar is closed */} {!visible && } ); } // Mobile implementation with PrimeReact's Sidebar return ( <> {/* Mobile toggle button - only shown when sidebar is closed */} {!visible && (
    )} {/* Mobile sidebar */}

    Course Lessons

      {lessons.map((lesson, index) => ( ))}
    ); }; export default CourseSidebar;