'use client'; import { useState, useEffect, useCallback } from 'react'; import Image from 'next/image'; import Link from 'next/link'; import { useLanguage } from '@/context/LanguageContext'; import Button from '@/components/ui/Button'; import { ChevronLeftIcon, ChevronRightIcon, ArrowRightIcon } from '@heroicons/react/24/outline'; export interface CarouselImage { src: string; alt: string; } interface MediaCarouselSectionProps { images: CarouselImage[]; } export default function MediaCarouselSection({ images }: MediaCarouselSectionProps) { const { t } = useLanguage(); const [currentIndex, setCurrentIndex] = useState(0); const [isAutoPlaying, setIsAutoPlaying] = useState(true); const [touchStart, setTouchStart] = useState(null); const [touchEnd, setTouchEnd] = useState(null); const goToNext = useCallback(() => { setCurrentIndex((prev) => (prev + 1) % images.length); }, [images.length]); const goToPrevious = useCallback(() => { setCurrentIndex((prev) => (prev - 1 + images.length) % images.length); }, [images.length]); const goToSlide = (index: number) => { setCurrentIndex(index); setIsAutoPlaying(false); // Resume auto-play after 5 seconds of inactivity setTimeout(() => setIsAutoPlaying(true), 5000); }; // Auto-play functionality useEffect(() => { if (!isAutoPlaying) return; const interval = setInterval(goToNext, 4000); return () => clearInterval(interval); }, [isAutoPlaying, goToNext]); // Touch handlers for swipe gestures const handleTouchStart = (e: React.TouchEvent) => { setTouchEnd(null); setTouchStart(e.targetTouches[0].clientX); }; const handleTouchMove = (e: React.TouchEvent) => { setTouchEnd(e.targetTouches[0].clientX); }; const handleTouchEnd = () => { if (!touchStart || !touchEnd) return; const distance = touchStart - touchEnd; const minSwipeDistance = 50; if (Math.abs(distance) > minSwipeDistance) { if (distance > 0) { goToNext(); } else { goToPrevious(); } setIsAutoPlaying(false); setTimeout(() => setIsAutoPlaying(true), 5000); } }; // Keyboard navigation useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'ArrowLeft') { goToPrevious(); setIsAutoPlaying(false); setTimeout(() => setIsAutoPlaying(true), 5000); } else if (e.key === 'ArrowRight') { goToNext(); setIsAutoPlaying(false); setTimeout(() => setIsAutoPlaying(true), 5000); } }; window.addEventListener('keydown', handleKeyDown); return () => window.removeEventListener('keydown', handleKeyDown); }, [goToNext, goToPrevious]); // Don't render if no images if (images.length === 0) { return null; } return (
{/* Header */}

{t('home.carousel.title')}

{t('home.carousel.subtitle')}

{/* Carousel Container */}
{/* Main Image Container */}
{images.map((image, index) => (
{image.alt}
))} {/* Soft gradient overlay for polish */}
{/* Navigation Arrows */} {/* Dots Navigation */}
{images.map((_, index) => (
{/* CTA Section - Outside carousel */}
); }