import React, { useState, useRef, useEffect } from 'react'; import ContentCard from './ContentCard'; import { ChevronLeft, ChevronRight } from 'lucide-react'; interface ContentItem { type: 'movie' | 'tvshow'; title: string; image: string; description?: string; genre?: string[]; year?: number | string; } interface ContentRowProps { title: string; items: ContentItem[]; } const ContentRow: React.FC = ({ title, items }) => { const rowRef = useRef(null); const [showLeftButton, setShowLeftButton] = useState(false); const [showRightButton, setShowRightButton] = useState(true); // Handle scroll events to show/hide buttons const handleScroll = () => { if (rowRef.current) { const { scrollLeft, scrollWidth, clientWidth } = rowRef.current; setShowLeftButton(scrollLeft > 20); setShowRightButton(scrollLeft < scrollWidth - clientWidth - 20); } }; // Set up scroll listeners and initial state useEffect(() => { handleScroll(); window.addEventListener('resize', handleScroll); return () => window.removeEventListener('resize', handleScroll); }, [items]); const scroll = (direction: 'left' | 'right') => { if (rowRef.current) { const card = rowRef.current.querySelector('.card-hover'); const cardWidth = card ? card.clientWidth + 16 : 280; // Card width + margin const scrollAmount = direction === 'left' ? -cardWidth * 3 : cardWidth * 3; rowRef.current.scrollBy({ left: scrollAmount, behavior: 'smooth' }); } }; // Don't render the row if there are no items if (items.length === 0) { return null; } return (

{title}

{/* Left scroll button */} {/* Content row */}
{items.map((item, index) => (
))}
{/* Right scroll button */}
); }; export default ContentRow;