"use client"; import Image from "next/image"; import { useCallback, useEffect, useMemo, useState } from "react"; import { Icon } from "@iconify/react"; import { Badge, Typography } from "poyraz-ui/atoms"; import { StaggerContainer, StaggerItem } from "@/components/motion-wrapper"; import type { GalleryItem } from "@/data/gallery"; type GalleryContentProps = { items: GalleryItem[]; }; export function GalleryContent({ items }: GalleryContentProps) { const [activeCategory, setActiveCategory] = useState("All"); const [lightboxIndex, setLightboxIndex] = useState(null); // Keyboard navigation for lightbox useEffect(() => { if (lightboxIndex === null) return; const handleKeyDown = (e: KeyboardEvent) => { if (e.key === "Escape") { setLightboxIndex(null); } else if (e.key === "ArrowLeft") { setLightboxIndex((prev) => (prev !== null && prev > 0 ? prev - 1 : prev)); } else if (e.key === "ArrowRight") { setLightboxIndex((prev) => prev !== null && prev < items.length - 1 ? prev + 1 : prev, ); } }; window.addEventListener("keydown", handleKeyDown); return () => window.removeEventListener("keydown", handleKeyDown); }, [lightboxIndex, items.length]); const categories = useMemo(() => { const cats = new Set(items.map((item) => item.category)); return ["All", ...Array.from(cats)].sort(); }, [items]); const filteredItems = useMemo(() => { if (activeCategory === "All") return items; return items.filter((item) => item.category === activeCategory); }, [items, activeCategory]); const openLightbox = useCallback( (item: GalleryItem) => { const index = items.findIndex((i) => i.id === item.id); if (index !== -1) { setLightboxIndex(index); } }, [items], ); const closeLightbox = useCallback(() => { setLightboxIndex(null); }, []); const lightboxItem = lightboxIndex !== null ? items[lightboxIndex] : null; return ( <>
{categories.length > 1 && (
{categories.map((category) => ( ))}
)} {filteredItems.length === 0 ? (
Henüz bu kategoride görsel bulunmuyor.
) : ( {filteredItems.map((item) => (
openLightbox(item)} > {item.title}
{item.title} {item.category}
))} )}
{/* Lightbox / Modal */} {lightboxItem && (
{lightboxIndex! > 0 && ( )} {lightboxIndex! < items.length - 1 && ( )}
e.stopPropagation()} >
{lightboxItem.title}
{lightboxItem.title} {lightboxItem.category}
{lightboxIndex! + 1} / {items.length}
{lightboxItem.description && ( {lightboxItem.description} )}
)} ); }