'use client'; import React, { useRef, useState, useEffect } from 'react'; import { ChevronLeft, ChevronRight } from 'lucide-react'; import { IconButton } from '@/ui/IconButton'; import { Box } from '@/ui/Box'; import { Heading } from '@/ui/Heading'; import { Text } from '@/ui/Text'; interface CarouselProps { children: React.ReactNode; title?: string; count?: number; } export function Carousel({ children, title, count }: CarouselProps) { const scrollRef = useRef(null); const [showLeft, setShowLeft] = useState(false); const [showRight, setShowRight] = useState(true); const checkScroll = () => { if (scrollRef.current) { const { scrollLeft, scrollWidth, clientWidth } = scrollRef.current; setShowLeft(scrollLeft > 10); setShowRight(scrollLeft < scrollWidth - clientWidth - 10); } }; useEffect(() => { checkScroll(); window.addEventListener('resize', checkScroll); return () => window.removeEventListener('resize', checkScroll); }, []); const scroll = (direction: 'left' | 'right') => { if (scrollRef.current) { const { clientWidth } = scrollRef.current; const scrollAmount = clientWidth * 0.8; scrollRef.current.scrollBy({ left: direction === 'left' ? -scrollAmount : scrollAmount, behavior: 'smooth' }); } }; return ( {/* Header with Title and Controls */} {title && ( {title} )} {count !== undefined && ( {count} )} scroll('left')} variant="secondary" size="sm" disabled={!showLeft} className={`transition-opacity duration-300 ${showLeft ? 'opacity-100' : 'opacity-30'}`} /> scroll('right')} variant="secondary" size="sm" disabled={!showRight} className={`transition-opacity duration-300 ${showRight ? 'opacity-100' : 'opacity-30'}`} /> {/* Scroll Area with Fades */} {/* Left Fade */} {/* Scroll Container */} {React.Children.map(children, (child) => ( {child} ))} {/* Right Fade */} ); }