import React, { useEffect, useState } from 'react'; import Icon from '../../shared/components/icon'; export interface GalleryImage { src: string; alt?: string; caption?: string; } export interface GalleryProps { title?: string; intro?: string; images: GalleryImage[]; } const PhotoGallery: React.FC = ({ images, title, intro }) => { const [activeIndex, setActiveIndex] = useState(null); const isOpen = activeIndex !== null; const activeImage = activeIndex !== null ? images[activeIndex] : null; const close = () => setActiveIndex(null); const next = () => { if (activeIndex === null) return; setActiveIndex((activeIndex + 1) % images.length); }; const prev = () => { if (activeIndex === null) return; setActiveIndex((activeIndex - 1 + images.length) % images.length); }; useEffect(() => { if (!isOpen) return; const onKeyDown = (e: KeyboardEvent) => { if (e.key === 'Escape') close(); if (e.key === 'ArrowRight') next(); if (e.key === 'ArrowLeft') prev(); }; document.addEventListener('keydown', onKeyDown); document.body.style.overflow = 'hidden'; return () => { document.removeEventListener('keydown', onKeyDown); document.body.style.overflow = ''; }; }, [isOpen, activeIndex, images.length]); if (!images.length) { return (

No photos available.

); } const big = images[0]; const thumbs = images.slice(1, 6); const extraCount = Math.max(0, images.length - 6); const openAt = (index: number) => { if (!images[index]) return; setActiveIndex(index); }; return (
{thumbs.map((img, i) => { const realIndex = i + 1; const isLastThumbSlot = i === 4; const shouldShowMoreOverlay = isLastThumbSlot && extraCount > 0; return ( ); })}
{isOpen && activeImage && (
{ if (e.target === e.currentTarget) close(); }}>
{activeImage.alt
{activeIndex + 1} / {images.length} {(activeImage.caption || activeImage.alt) && {activeImage.caption ?? activeImage.alt}}
)}

{title}

{intro}

); }; export default PhotoGallery;