'use client'; import React, { useState, useEffect, useRef } from 'react'; import { ChevronLeft, ChevronRight } from 'lucide-react'; import { Card, CardContent } from '@/components/ui/card'; import Image from 'next/image'; interface ImageCarouselProps { images: Array<{ src: string; alt?: string; title?: string; }>; autoScrollInterval?: number; className?: string; } export function ImageCarousel({ images, autoScrollInterval = 3000, className = '' }: ImageCarouselProps) { const [currentIndex, setCurrentIndex] = useState(0); const scrollRef = useRef(null); const itemWidth = 280; const gap = 16; // Auto-scroll functionality useEffect(() => { const timer = setInterval(() => { setCurrentIndex((prevIndex) => { const nextIndex = prevIndex + 1; return nextIndex >= images.length ? 0 : nextIndex; }); }, autoScrollInterval); return () => clearInterval(timer); }, [images.length, autoScrollInterval]); // Scroll to current index useEffect(() => { if (scrollRef.current) { scrollRef.current.scrollTo({ left: currentIndex * (itemWidth + gap), behavior: 'smooth' }); } }, [currentIndex, itemWidth, gap]); const handlePrevious = () => { setCurrentIndex((prevIndex) => { const nextIndex = prevIndex - 1; return nextIndex < 0 ? images.length - 1 : nextIndex; }); }; const handleNext = () => { setCurrentIndex((prevIndex) => { const nextIndex = prevIndex + 1; return nextIndex >= images.length ? 0 : nextIndex; }); }; if (images.length === 0) { return null; } return (
{/* Navigation buttons */} {/* Carousel container */}
{images.map((img, index) => (
{img.alt
))}
{/* Dots indicator */}
{images.map((_, index) => (
); }