import React, { useCallback, useEffect, useState } from 'react' import { AnimatePresence, motion } from 'framer-motion' import { ChevronLeftIcon, ChevronRightIcon, XIcon } from 'lucide-react' import { Reveal } from '../Reveal' import { SectionHeading } from '../SectionHeading' import { useSite } from '../../api' import { AddItemButton, EditableItem } from '../../admin/Editable' export function Gallery() { const { gallery } = useSite() const [active, setActive] = useState(null) const close = useCallback(() => setActive(null), []) const step = useCallback((dir: number) => { setActive((prev) => (prev === null ? prev : (prev + dir + gallery.length) % gallery.length)) }, [gallery.length]) useEffect(() => { if (active === null) return const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') close() if (e.key === 'ArrowRight') step(-1) if (e.key === 'ArrowLeft') step(1) } window.addEventListener('keydown', onKey) return () => window.removeEventListener('keydown', onKey) }, [active, close, step]) return (
{gallery.map((image, i) => ( ))}
{active !== null && gallery[active] && ( e.stopPropagation()} /> )}
) }