'use client' import Image from 'next/image' import { useCallback, useEffect, useState } from 'react' type Photo = { src: string; alt: string } type Labels = { photoClose: string; photoPrev: string; photoNext: string } export function PhotoGallery({ photos, t }: { photos: Photo[]; t: Labels }) { const [open, setOpen] = useState(null) const count = photos.length const step = useCallback((d: number) => setOpen(i => (i === null ? i : (i + d + count) % count)), [count]) useEffect(() => { if (open === null) return const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') setOpen(null) else if (e.key === 'ArrowRight') step(1) else if (e.key === 'ArrowLeft') step(-1) } window.addEventListener('keydown', onKey) return () => window.removeEventListener('keydown', onKey) }, [open, step]) if (count === 0) return null const btn = 'absolute flex h-11 w-11 items-center justify-center rounded-full bg-paper text-2xl text-graphite' return <> {open !== null &&
setOpen(null)}> {photos[open].alt} e.stopPropagation()} className="h-auto max-h-[90vh] w-auto max-w-full object-contain" /> {count > 1 && <> }
} }