forked from UKSOURCE/ipv6
351 lines
15 KiB
TypeScript
351 lines
15 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[];
|
|
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<number | null>(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 (
|
|
<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>
|
|
|
|
{/* Gallery Section */}
|
|
<section className="py-12 lg:py-20 px-[var(--spacing-gutter)] max-w-hd mx-auto">
|
|
|
|
{/* Step Timeline Navigation */}
|
|
<div className="mb-10 max-w-4xl mx-auto px-4">
|
|
<div className="relative flex justify-between items-center">
|
|
{/* Timeline track behind steps */}
|
|
<div className="absolute left-0 right-0 h-[2px] bg-white/10 -z-10" />
|
|
<div
|
|
className="absolute left-0 h-[2px] bg-primary transition-all duration-500 -z-10"
|
|
style={{ width: `${(activeEventIndex / (gallery.events.length - 1)) * 100}%` }}
|
|
/>
|
|
|
|
{gallery.events.map((event: EventItem, idx: number) => {
|
|
const isActive = idx === activeEventIndex;
|
|
const isPassed = idx < activeEventIndex;
|
|
|
|
return (
|
|
<button
|
|
key={event.id}
|
|
type="button"
|
|
onClick={() => setActiveEventIndex(idx)}
|
|
className="flex flex-col items-center group cursor-pointer relative focus:outline-none"
|
|
title={event.title}
|
|
>
|
|
{/* Step circle */}
|
|
<div
|
|
className={[
|
|
"w-8 h-8 rounded-full flex items-center justify-center font-[var(--font-label-caps)] text-xs font-bold transition-all duration-300 border-2 z-10",
|
|
isActive
|
|
? "bg-background border-primary text-primary status-led shadow-[0_0_12px_rgba(197,160,89,0.6)] scale-110"
|
|
: isPassed
|
|
? "bg-primary border-primary text-on-primary"
|
|
: "bg-surface-container-high border-white/10 text-on-surface-variant/40 hover:border-white/30 hover:text-on-surface"
|
|
].join(" ")}
|
|
>
|
|
{idx + 1}
|
|
</div>
|
|
</button>
|
|
);
|
|
})}
|
|
</div>
|
|
</div>
|
|
|
|
{/* Active Event Grid Container */}
|
|
{activeEvent && (
|
|
<div className="glass-panel p-6 sm:p-10 lg:p-16 rounded-[2rem] lg:rounded-[3rem] border border-primary/20 hover:border-primary/30 shadow-2xl transition-all duration-300">
|
|
|
|
{/* Top Navigation Control Header */}
|
|
<div className="flex justify-between items-center mb-10 border-b border-white/5 pb-6">
|
|
<button
|
|
type="button"
|
|
onClick={goToNewerEvent}
|
|
disabled={activeEventIndex === 0}
|
|
className="flex items-center gap-1.5 text-xs sm:text-sm font-bold uppercase tracking-wider text-on-surface-variant/60 hover:text-primary disabled:opacity-20 disabled:pointer-events-none transition-colors duration-200 focus:outline-none"
|
|
>
|
|
<span className="material-symbols-outlined text-lg">arrow_back</span>
|
|
<span className="hidden sm:inline">{lang === "vi" ? "Sự kiện mới hơn" : "Newer Event"}</span>
|
|
</button>
|
|
|
|
<span className="font-[var(--font-label-caps)] text-xs sm:text-sm text-primary tracking-widest bg-primary/5 border border-primary/20 px-4 py-2 rounded-xl">
|
|
{lang === "vi"
|
|
? `SỰ KIỆN ${activeEventIndex + 1} / ${gallery.events.length}`
|
|
: `EVENT ${activeEventIndex + 1} OF ${gallery.events.length}`
|
|
}
|
|
</span>
|
|
|
|
<button
|
|
type="button"
|
|
onClick={goToOlderEvent}
|
|
disabled={activeEventIndex === gallery.events.length - 1}
|
|
className="flex items-center gap-1.5 text-xs sm:text-sm font-bold uppercase tracking-wider text-on-surface-variant/60 hover:text-primary disabled:opacity-20 disabled:pointer-events-none transition-colors duration-200 focus:outline-none"
|
|
>
|
|
<span className="hidden sm:inline">{lang === "vi" ? "Sự kiện cũ hơn" : "Older Event"}</span>
|
|
<span className="material-symbols-outlined text-lg">arrow_forward</span>
|
|
</button>
|
|
</div>
|
|
|
|
{/* Event Info Header */}
|
|
<div className="max-w-4xl mb-12">
|
|
<h2 className="text-2xl sm:text-3xl lg:text-4xl font-[var(--font-display-lg)] text-primary mb-4 leading-tight">
|
|
{activeEvent.title}
|
|
</h2>
|
|
|
|
<div className="flex flex-wrap items-center gap-4 text-xs uppercase tracking-wider text-on-surface-variant/50 font-[var(--font-label-caps)] mb-6">
|
|
<div className="flex items-center gap-1.5 bg-surface-container-high px-3.5 py-2 rounded-xl border border-white/5">
|
|
<span className="material-symbols-outlined text-base text-primary">calendar_today</span>
|
|
<span>{activeEvent.date}</span>
|
|
</div>
|
|
|
|
{activeEvent.googleDriveUrl && activeEvent.googleDriveUrl.trim() !== "" && (
|
|
<a
|
|
href={activeEvent.googleDriveUrl}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
className="flex items-center gap-2 bg-surface-container-high hover:bg-surface-container-highest px-3.5 py-2 rounded-xl border border-white/5 text-primary text-xs font-bold transition-all duration-200 focus:outline-none"
|
|
>
|
|
<i className="fab fa-google-drive text-sm"></i>
|
|
<span>{lang === "vi" ? "Xem Full Album trên Drive" : "View Full Album on Drive"}</span>
|
|
</a>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
{/* Dynamic Mosaic Grid or Coming Soon Placeholder */}
|
|
{activeEvent.images.length === 0 ? (
|
|
<div className="flex flex-col items-center justify-center py-20 px-6 border border-white/5 bg-white/[0.01] rounded-2xl">
|
|
<span className="material-symbols-outlined text-5xl text-primary/45 mb-4">image</span>
|
|
<p className="text-on-surface-variant/60 font-sans text-sm sm:text-base text-center max-w-md">
|
|
{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."
|
|
}
|
|
</p>
|
|
</div>
|
|
) : (
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-6">
|
|
{activeEvent.images.map((imgUrl, i) => (
|
|
<div
|
|
key={i}
|
|
className={[
|
|
getMosaicClasses(i, activeEvent.images.length),
|
|
"overflow-hidden rounded-2xl border border-white/10 group cursor-pointer relative",
|
|
].join(" ")}
|
|
onClick={() => openLightbox(i)}
|
|
>
|
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
|
<img
|
|
src={getImgSrc(imgUrl)}
|
|
alt={`${activeEvent.title} Highlight ${i + 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 shadow-lg">
|
|
<span className="material-symbols-outlined text-2xl">zoom_in</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
)}
|
|
|
|
</div>
|
|
)}
|
|
</section>
|
|
|
|
{/* Invitation Section */}
|
|
<ReadyToJoin data={gallery.join} />
|
|
|
|
{/* Lightbox Overlay */}
|
|
{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] focus:outline-none"
|
|
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 focus:outline-none"
|
|
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 focus:outline-none"
|
|
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)]">
|
|
{lang === "vi"
|
|
? `Hình ảnh ${lightboxImageIndex + 1} trên ${activeEvent.images.length}`
|
|
: `Image ${lightboxImageIndex + 1} of ${activeEvent.images.length}`
|
|
}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</main>
|
|
);
|
|
}
|