"use client"; import { useState, useEffect } from "react"; import { useTranslation } from "@/app/hooks/useTranslation"; import ReadyToJoin from "./ReadyToJoin"; const BASE = process.env.NEXT_PUBLIC_BASE_PATH || ""; type EventItem = { id: number; title: string; location: string; date: string; description: string; images: string[]; }; export default function GalleryPageClient() { const { gallery } = useTranslation(); // Lightbox State const [lightboxEventId, setLightboxEventId] = useState(null); const [lightboxImageIndex, setLightboxImageIndex] = useState(null); // Helper to format image source path const getImgSrc = (src: string) => { if (src.startsWith("http")) return src; return `${BASE}${src}`; }; // Keyboard navigation for Lightbox useEffect(() => { if (lightboxEventId === null || lightboxImageIndex === null) return; const activeEvent = gallery.events.find((e: EventItem) => e.id === lightboxEventId); if (!activeEvent) return; const handleKeyDown = (e: KeyboardEvent) => { if (e.key === "Escape") { closeLightbox(); } else if (e.key === "ArrowRight") { setLightboxImageIndex((prev) => (prev! + 1) % activeEvent.images.length); } else if (e.key === "ArrowLeft") { setLightboxImageIndex((prev) => (prev! - 1 + activeEvent.images.length) % activeEvent.images.length); } }; window.addEventListener("keydown", handleKeyDown); return () => { window.removeEventListener("keydown", handleKeyDown); }; }, [lightboxEventId, lightboxImageIndex, gallery.events]); const openLightbox = (eventId: number, imgIndex: number) => { setLightboxEventId(eventId); setLightboxImageIndex(imgIndex); document.body.style.overflow = "hidden"; }; const closeLightbox = () => { setLightboxEventId(null); setLightboxImageIndex(null); document.body.style.overflow = ""; }; // Find active lightbox image and event const activeEvent = lightboxEventId !== null ? gallery.events.find((e: EventItem) => e.id === lightboxEventId) : null; const activeImage = activeEvent && lightboxImageIndex !== null ? activeEvent.images[lightboxImageIndex] : null; return (
{/* Hero Header */}
{gallery.hero.eyebrow}

{gallery.hero.title}

{gallery.hero.description}

{/* Visual Gallery section */}
{gallery.events.map((event: EventItem) => (
{/* Event details */}

{event.title}

{event.description}

{/* Meta details */}
location_on {event.location}
calendar_today {event.date}
{/* Collage gallery grid */}
{/* Large image (left) */}
openLightbox(event.id, 0)} > {/* eslint-disable-next-line @next/next/no-img-element */} {`${event.title}
zoom_in
{/* Stacked images (right) */}
{event.images.slice(1, 3).map((imgUrl, i) => (
openLightbox(event.id, i + 1)} > {/* eslint-disable-next-line @next/next/no-img-element */} {`${event.title}
zoom_in
))}
))}
{/* Invitation Section */} {/* Lightbox Overlay */} {lightboxEventId !== null && lightboxImageIndex !== null && activeEvent && activeImage && (
{/* Close button */} {/* Lightbox content container */}
e.stopPropagation()} > {/* Prev arrow */} {/* Active Image */}
{/* eslint-disable-next-line @next/next/no-img-element */} {`${activeEvent.title}
{/* Next arrow */}
{/* Info bar below image */}
e.stopPropagation()} >

{activeEvent.title}

{useTranslation().lang === "vi" ? `Hình ảnh ${lightboxImageIndex + 1} trên ${activeEvent.images.length}` : `Image ${lightboxImageIndex + 1} of ${activeEvent.images.length}` }

)}
); }