"use client"; import { useState, useEffect } from "react"; import Image from "next/image"; import { Button } from "@/components/ui/button"; import { ChevronLeft, ChevronRight, ArrowLeft, Download } from "lucide-react"; // Added Download import { useRouter } from "next/navigation"; import JSZip from "jszip"; import { saveAs } from "file-saver"; interface ImageSliderProps { images: string[]; } const ImageSlider: React.FC = ({ images }) => { const [currentIndex, setCurrentIndex] = useState(0); const [isDownloading, setIsDownloading] = useState(false); const [isHovered, setIsHovered] = useState(false); // New state for hover const router = useRouter(); const goToPrevious = () => { const isFirstImage = currentIndex === 0; const newIndex = isFirstImage ? images.length - 1 : currentIndex - 1; setCurrentIndex(newIndex); }; const goToNext = () => { const isLastImage = currentIndex === images.length - 1; const newIndex = isLastImage ? 0 : currentIndex + 1; setCurrentIndex(newIndex); }; useEffect(() => { let timer: NodeJS.Timeout; if (!isHovered) { // Only set timer if not hovered timer = setTimeout(() => { goToNext(); }, 5000); // Change image every 5 seconds } return () => clearTimeout(timer); }, [currentIndex, images.length, isHovered, goToNext]); // Added isHovered and goToNext to dependency array const handleDownloadAll = async () => { if (!images || images.length === 0) return; setIsDownloading(true); const zip = new JSZip(); try { for (let i = 0; i < images.length; i++) { const response = await fetch(images[i]); const blob = await response.blob(); // Extract filename from path, or use index as fallback const filename = images[i].substring(images[i].lastIndexOf("/") + 1) || `image_${i + 1}.png`; zip.file(filename, blob); } const zipBlob = await zip.generateAsync({ type: "blob" }); saveAs(zipBlob, "images.zip"); } catch (error) { console.error("Error zipping images:", error); // Handle error (e.g., show a notification to the user) } finally { setIsDownloading(false); } }; if (!images || images.length === 0) { return

No images to display.

; } return (
setIsHovered(true)} // Set hovered to true onMouseLeave={() => setIsHovered(false)} // Set hovered to false >
{" "} {/* Added mt-12 to make space for back button */}
{images.map((src, index) => (
{`Slide
))}
{" "} {/* Changed py-4 to pt-4 pb-1 to move dots lower */} {images.map((_, index) => (
); }; export default ImageSlider;