"use client"; import { useState } from "react"; import Image from "next/image"; interface PropertyGalleryProps { images: string[]; title: string; } export default function PropertyGallery({ images, title }: PropertyGalleryProps) { const [activeImage, setActiveImage] = useState(0); const [showLightbox, setShowLightbox] = useState(false); const [lightboxIndex, setLightboxIndex] = useState(0); const openLightbox = (index: number) => { setLightboxIndex(index); setShowLightbox(true); document.body.style.overflow = 'hidden'; }; const closeLightbox = () => { setShowLightbox(false); document.body.style.overflow = 'unset'; }; // Ensure we have at least 5 images for the gallery (1 big + 4 small) const displayImages = [...images]; while (displayImages.length < 5) { displayImages.push("/assets/images/image.png"); } const nextImage = () => { setLightboxIndex((prev) => (prev + 1) % displayImages.length); }; const prevImage = () => { setLightboxIndex((prev) => (prev - 1 + displayImages.length) % displayImages.length); }; return ( <>
openLightbox(activeImage)}> {title}
Click to enlarge
{displayImages.slice(0, 3).map((img, idx) => (
setActiveImage(idx)} className={`relative w-full h-full rounded-xl overflow-hidden cursor-pointer transition-all duration-300 ${activeImage === idx ? 'ring-4 ring-primary scale-95' : 'hover:scale-95' }`} > {`View
))} {/* View All Photos Button (4th slot) */}
openLightbox(0)} className="relative w-full h-full rounded-xl overflow-hidden cursor-pointer group" > View all photos
View All Photos ({displayImages.length} images)
{/* Lightbox Modal */} {showLightbox && (
{/* Close Button */} {/* Image Counter */}
{lightboxIndex + 1} / {displayImages.length}
{/* Previous Button */} {/* Main Image */}
{`${title}
{/* Next Button */} {/* Thumbnail Strip */}
{displayImages.map((img, idx) => (
setLightboxIndex(idx)} className={`relative w-20 h-20 flex-shrink-0 rounded-lg overflow-hidden cursor-pointer transition-all ${lightboxIndex === idx ? 'ring-4 ring-white scale-110' : 'opacity-60 hover:opacity-100' }`} > {`Thumbnail
))}
)} ); }