"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[]; googleDriveUrl: string; }; export default function GalleryPageClient() { const { gallery, lang } = useTranslation(); // Active Event Index (0: latest event, 7: oldest event) const [activeEventIndex, setActiveEventIndex] = useState(0); // Lightbox State const [lightboxImageIndex, setLightboxImageIndex] = useState(null); // Active event object const activeEvent = gallery.events[activeEventIndex] as EventItem; // 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 (lightboxImageIndex === null || !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); }; }, [lightboxImageIndex, activeEvent]); const openLightbox = (imgIndex: number) => { setLightboxImageIndex(imgIndex); document.body.style.overflow = "hidden"; }; const closeLightbox = () => { setLightboxImageIndex(null); document.body.style.overflow = ""; }; const goToNewerEvent = () => { if (activeEventIndex > 0) { setActiveEventIndex(activeEventIndex - 1); } }; const goToOlderEvent = () => { if (activeEventIndex < gallery.events.length - 1) { setActiveEventIndex(activeEventIndex + 1); } }; const activeImage = activeEvent && lightboxImageIndex !== null ? activeEvent.images[lightboxImageIndex] : null; // Helper to determine CSS classes for the dynamic mosaic const getMosaicClasses = (i: number, total: number) => { // If very few images, keep it simple if (total < 3) { return "h-[240px] sm:h-[320px]"; } // Dynamic grid classes switch (i) { case 0: // Spotlight spans 2 columns & 2 rows on desktop return "md:col-span-2 md:row-span-2 h-[260px] sm:h-[360px] md:h-[500px]"; default: // Adjust the last image to prevent layout gaps if (i === total - 1) { if (total === 4 || total === 7) { return "md:col-span-2 h-[180px] sm:h-[240px]"; } if (total === 5 || total === 8) { return "md:col-span-2 h-[180px] sm:h-[240px]"; } if (total === 10) { return "md:col-span-3 h-[200px] sm:h-[280px]"; } } return "h-[180px] sm:h-[240px]"; } }; return (
{/* Hero Header */}
{gallery.hero.eyebrow}

{gallery.hero.title}

{gallery.hero.description}

{/* Gallery Section */}
{/* Step Timeline Navigation */}
{/* Timeline track behind steps */}
{gallery.events.map((event: EventItem, idx: number) => { const isActive = idx === activeEventIndex; const isPassed = idx < activeEventIndex; return ( ); })}
{/* Active Event Grid Container */} {activeEvent && (
{/* Top Navigation Control Header */}
{lang === "vi" ? `SỰ KIỆN ${activeEventIndex + 1} / ${gallery.events.length}` : `EVENT ${activeEventIndex + 1} OF ${gallery.events.length}` }
{/* Event Info Header */}

{activeEvent.title}

calendar_today {activeEvent.date}
{activeEvent.googleDriveUrl && activeEvent.googleDriveUrl.trim() !== "" && ( {lang === "vi" ? "Xem Full Album trên Drive" : "View Full Album on Drive"} )}
{/* Dynamic Mosaic Grid or Coming Soon Placeholder */} {activeEvent.images.length === 0 ? (
image

{lang === "vi" ? "Hình ảnh nổi bật cho sự kiện này hiện đang được cập nhật." : "Highlight images for this event are currently being updated." }

) : (
{activeEvent.images.map((imgUrl, i) => (
openLightbox(i)} > {/* eslint-disable-next-line @next/next/no-img-element */} {`${activeEvent.title}
zoom_in
))}
)}
)}
{/* Invitation Section */} {/* Lightbox Overlay */} {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}

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

)}
); }