import React, { useRef, useState, useEffect, useCallback } from 'react'; import { CourseCard } from './CourseCard'; import { Section, Course } from '../types'; import { ChevronRight, ChevronLeft } from 'lucide-react'; interface CourseRowProps { section: Section; onCourseClick?: (course: Course) => void; } export const CourseRow: React.FC = ({ section, onCourseClick }) => { const containerRef = useRef(null); const isMouseDownRef = useRef(false); const startXRef = useRef(0); const scrollLeftRef = useRef(0); const draggedDistanceRef = useRef(0); const [canScrollLeft, setCanScrollLeft] = useState(false); const [canScrollRight, setCanScrollRight] = useState(true); const [isDragging, setIsDragging] = useState(false); const checkScrollBoundaries = useCallback(() => { if (!containerRef.current) return; const { scrollLeft, scrollWidth, clientWidth } = containerRef.current; setCanScrollLeft(scrollLeft > 20); setCanScrollRight(scrollLeft + clientWidth < scrollWidth - 20); }, []); useEffect(() => { checkScrollBoundaries(); window.addEventListener('resize', checkScrollBoundaries); return () => window.removeEventListener('resize', checkScrollBoundaries); }, [checkScrollBoundaries, section.courses]); // Arrow button handlers const handleScroll = (direction: 'left' | 'right') => { if (!containerRef.current) return; const scrollAmount = containerRef.current.clientWidth * 0.75; containerRef.current.scrollBy({ left: direction === 'left' ? -scrollAmount : scrollAmount, behavior: 'smooth' }); }; // Mouse Drag-to-Scroll Handlers const handleMouseDown = (e: React.MouseEvent) => { if (!containerRef.current) return; // Don't drag if clicking buttons or specific interactive items isMouseDownRef.current = true; startXRef.current = e.pageX - containerRef.current.offsetLeft; scrollLeftRef.current = containerRef.current.scrollLeft; draggedDistanceRef.current = 0; setIsDragging(false); }; const handleMouseMove = (e: React.MouseEvent) => { if (!isMouseDownRef.current || !containerRef.current) return; e.preventDefault(); const x = e.pageX - containerRef.current.offsetLeft; const walk = (x - startXRef.current) * 1.5; // Drag sensitivity multiplier draggedDistanceRef.current = Math.abs(walk); if (draggedDistanceRef.current > 6) { setIsDragging(true); containerRef.current.scrollLeft = scrollLeftRef.current - walk; } }; const handleMouseUp = () => { isMouseDownRef.current = false; setTimeout(() => { setIsDragging(false); draggedDistanceRef.current = 0; }, 50); }; const handleCardClick = (course: Course) => { // Only trigger play/open if user wasn't dragging if (draggedDistanceRef.current < 10) { onCourseClick?.(course); } }; return (
{/* Title Header */}

{section.title}

{section.courses.length} {section.courses.length === 1 ? 'curso' : 'cursos'}
{/* Inline Navigation Arrows for Desktop */}
{/* Horizontal Carousel Container */}
{/* Floating Side Arrow Left (Hover Overlay) */} {canScrollLeft && ( )} {/* Scroll Container with drag-to-scroll */}
{section.courses.map((course) => (
))} {/* Padding at the end */}
{/* Floating Side Arrow Right (Hover Overlay) */} {canScrollRight && ( )} {/* Subtle Vignette on the right */}
); };