"use client"; import { useTranslations } from 'next-intl'; import { motion, AnimatePresence } from 'framer-motion'; import { Instagram } from '@/components/InstagramIcon'; import { useState, useEffect } from 'react'; import { X, ChevronLeft, ChevronRight } from 'lucide-react'; export default function Gallery({ dbGallery = [] }: { dbGallery?: any[] }) { const t = useTranslations('Gallery'); // Fallback to placeholder images if database is empty const images = dbGallery.length > 0 ? dbGallery : Array.from({ length: 12 }).map((_, i) => ({ id: `fallback-${i}`, src: `https://picsum.photos/600/${400 + (i % 5) * 50}?random=${30 + i}`, alt: `Gallery ${i + 1}`, })); const [selectedIndex, setSelectedIndex] = useState(null); // Close lightbox on escape key useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Escape') setSelectedIndex(null); if (e.key === 'ArrowRight' && selectedIndex !== null) { setSelectedIndex((prev) => (prev !== null ? (prev + 1) % images.length : null)); } if (e.key === 'ArrowLeft' && selectedIndex !== null) { setSelectedIndex((prev) => (prev !== null ? (prev - 1 + images.length) % images.length : null)); } }; window.addEventListener('keydown', handleKeyDown); return () => window.removeEventListener('keydown', handleKeyDown); }, [selectedIndex, images.length]); return ( ); }