"use client"; import { useState, useEffect, useCallback } from "react"; import { motion, AnimatePresence } from "framer-motion"; import { ChevronLeft, ChevronRight } from "lucide-react"; interface GalleryProps { images: string[]; } export default function ImageCarousel({ images }: GalleryProps) { const [[page, direction], setPage] = useState([0, 0]); const [isAutoPlaying, setIsAutoPlaying] = useState(true); const imageIndex = Math.abs(page % images.length); const paginate = useCallback((newDirection: number) => { setPage([page + newDirection, newDirection]); }, [page]); // AUTO-PLAY LOGIC useEffect(() => { if (!isAutoPlaying) return; const interval = setInterval(() => { paginate(1); }, 5000); // 5 seconds is the "sweet spot" for technical analysis return () => clearInterval(interval); }, [paginate, isAutoPlaying]); const variants = { enter: (direction: number) => ({ x: direction > 0 ? 1000 : -1000, opacity: 0, }), center: { zIndex: 1, x: 0, opacity: 1 }, exit: (direction: number) => ({ zIndex: 0, x: direction < 0 ? 1000 : -1000, opacity: 0, }), }; return (
setIsAutoPlaying(false)} // Pause on hover onMouseLeave={() => setIsAutoPlaying(true)} // Resume when mouse leaves > setIsAutoPlaying(false)} // Kill auto-play on interaction onDragEnd={(e, { offset }) => { const swipe = Math.abs(offset.x) > 50; if (swipe) paginate(offset.x > 0 ? -1 : 1); }} className="absolute h-full w-full object-cover cursor-grab active:cursor-grabbing" /> {/* Navigation Arrows */}
{/* Progress Bar (Visual Timer) */} {isAutoPlaying && ( )}
); }