Files
ipv6-sims/app/components/gallery/GalleryPageClient.tsx
T
2026-05-28 19:37:12 +07:00

248 lines
11 KiB
TypeScript

"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<number | null>(null);
const [lightboxImageIndex, setLightboxImageIndex] = useState<number | null>(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 (
<main className="pt-16 lg:pt-20 min-h-screen bg-background text-on-surface">
{/* Hero Header */}
<section className="hero-glow py-20 lg:py-32 px-[var(--spacing-gutter)] text-center">
<div className="max-w-4xl mx-auto">
<span className="font-[var(--font-label-caps)] text-xs lg:text-sm text-primary block mb-4 lg:mb-6 tracking-[0.25em] uppercase">
{gallery.hero.eyebrow}
</span>
<h1 className="font-[var(--font-display-lg)] text-on-surface text-[clamp(2.5rem,6vw+1rem,5.5rem)] leading-none tracking-tight">
{gallery.hero.title}
</h1>
<p className="font-[var(--font-body-base)] text-on-surface-variant text-base lg:text-[20px] max-w-3xl mx-auto opacity-70 leading-relaxed mt-6">
{gallery.hero.description}
</p>
</div>
</section>
{/* Visual Gallery section */}
<section className="py-12 lg:py-20 px-[var(--spacing-gutter)] max-w-hd mx-auto">
<div className="flex flex-col gap-16 lg:gap-24">
{gallery.events.map((event: EventItem) => (
<div
key={event.id}
className="glass-panel p-6 sm:p-8 lg:p-12 rounded-3xl border border-primary/20 hover:border-primary/40 shadow-xl transition-all duration-300"
>
{/* Event details */}
<div className="flex flex-col lg:flex-row lg:items-start lg:justify-between mb-8 gap-4">
<div className="max-w-2xl">
<h2 className="text-xl sm:text-2xl lg:text-3xl font-[var(--font-display-lg)] text-primary mb-3">
{event.title}
</h2>
<p className="text-sm sm:text-base text-on-surface-variant/80 leading-relaxed font-sans">
{event.description}
</p>
</div>
{/* Meta details */}
<div className="flex flex-wrap items-center gap-4 lg:self-start lg:mt-2 text-xs uppercase tracking-wider text-on-surface-variant/60 font-[var(--font-label-caps)]">
<div className="flex items-center gap-1.5 bg-surface-container-high px-3 py-1.5 rounded-lg border border-white/5">
<span className="material-symbols-outlined text-base text-primary">location_on</span>
<span>{event.location}</span>
</div>
<div className="flex items-center gap-1.5 bg-surface-container-high px-3 py-1.5 rounded-lg border border-white/5">
<span className="material-symbols-outlined text-base text-primary">calendar_today</span>
<span>{event.date}</span>
</div>
</div>
</div>
{/* Collage gallery grid */}
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 lg:gap-6">
{/* Large image (left) */}
<div
className="md:col-span-2 overflow-hidden rounded-2xl border border-white/10 group cursor-pointer relative h-[240px] sm:h-[320px] md:h-[360px]"
onClick={() => openLightbox(event.id, 0)}
>
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
src={getImgSrc(event.images[0])}
alt={`${event.title} Highlight 1`}
className="w-full h-full object-cover transition-transform duration-700 group-hover:scale-105"
loading="lazy"
/>
<div className="absolute inset-0 bg-black/40 opacity-0 group-hover:opacity-100 transition-opacity duration-300 flex items-center justify-center">
<div className="w-12 h-12 rounded-full bg-primary/20 backdrop-blur-md flex items-center justify-center border border-primary/50 text-white">
<span className="material-symbols-outlined text-2xl">zoom_in</span>
</div>
</div>
</div>
{/* Stacked images (right) */}
<div className="flex flex-col gap-4 lg:gap-6">
{event.images.slice(1, 3).map((imgUrl, i) => (
<div
key={i}
className="flex-1 overflow-hidden rounded-2xl border border-white/10 group cursor-pointer relative h-[180px] sm:h-[220px] md:h-[168px] lg:h-[168px]"
onClick={() => openLightbox(event.id, i + 1)}
>
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
src={getImgSrc(imgUrl)}
alt={`${event.title} Highlight ${i + 2}`}
className="w-full h-full object-cover transition-transform duration-700 group-hover:scale-105"
loading="lazy"
/>
<div className="absolute inset-0 bg-black/40 opacity-0 group-hover:opacity-100 transition-opacity duration-300 flex items-center justify-center">
<div className="w-10 h-10 rounded-full bg-primary/20 backdrop-blur-md flex items-center justify-center border border-primary/50 text-white">
<span className="material-symbols-outlined text-xl">zoom_in</span>
</div>
</div>
</div>
))}
</div>
</div>
</div>
))}
</div>
</section>
{/* Invitation Section */}
<ReadyToJoin data={gallery.join} />
{/* Lightbox Overlay */}
{lightboxEventId !== null && lightboxImageIndex !== null && activeEvent && activeImage && (
<div
className="fixed inset-0 z-[100] flex flex-col justify-center items-center bg-black/95 backdrop-blur-md transition-opacity duration-300"
onClick={closeLightbox}
>
{/* Close button */}
<button
type="button"
className="absolute top-6 right-6 text-white/70 hover:text-white transition-colors p-2 z-[110]"
onClick={closeLightbox}
aria-label="Close Lightbox"
>
<span className="material-symbols-outlined text-4xl">close</span>
</button>
{/* Lightbox content container */}
<div
className="relative flex items-center justify-between w-full max-w-6xl px-4 md:px-12 h-[60vh] sm:h-[70vh] md:h-[80vh]"
onClick={(e) => e.stopPropagation()}
>
{/* Prev arrow */}
<button
type="button"
className="w-12 h-12 md:w-16 md:h-16 rounded-full bg-white/5 hover:bg-white/10 border border-white/10 text-white flex items-center justify-center transition-colors mr-2 active:scale-95"
onClick={() => setLightboxImageIndex((prev) => (prev! - 1 + activeEvent.images.length) % activeEvent.images.length)}
aria-label="Previous Image"
>
<span className="material-symbols-outlined text-2xl md:text-3xl">chevron_left</span>
</button>
{/* Active Image */}
<div className="flex-1 flex items-center justify-center h-full relative overflow-hidden select-none px-4">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
src={getImgSrc(activeImage)}
alt={`${activeEvent.title} Full Highlight`}
className="max-w-full max-h-full object-contain rounded-lg border border-white/5 shadow-2xl transition-all duration-300 animate-in fade-in zoom-in-95 duration-200"
/>
</div>
{/* Next arrow */}
<button
type="button"
className="w-12 h-12 md:w-16 md:h-16 rounded-full bg-white/5 hover:bg-white/10 border border-white/10 text-white flex items-center justify-center transition-colors ml-2 active:scale-95"
onClick={() => setLightboxImageIndex((prev) => (prev! + 1) % activeEvent.images.length)}
aria-label="Next Image"
>
<span className="material-symbols-outlined text-2xl md:text-3xl">chevron_right</span>
</button>
</div>
{/* Info bar below image */}
<div
className="text-center mt-6 px-6 max-w-2xl select-none"
onClick={(e) => e.stopPropagation()}
>
<h3 className="font-[var(--font-display-lg)] text-primary text-base sm:text-lg mb-1.5">
{activeEvent.title}
</h3>
<p className="text-on-surface-variant/60 text-xs sm:text-sm uppercase tracking-wider font-[var(--font-label-caps)]">
{useTranslation().lang === "vi"
? `Hình ảnh ${lightboxImageIndex + 1} trên ${activeEvent.images.length}`
: `Image ${lightboxImageIndex + 1} of ${activeEvent.images.length}`
}
</p>
</div>
</div>
)}
</main>
);
}