"use client"; import Image from "next/image"; import { useCallback, useEffect, useState } from "react"; import { Icon } from "@iconify/react"; import { Typography } from "poyraz-ui/atoms"; import { StaggerContainer, StaggerItem } from "@/components/motion-wrapper"; import { useTranslations } from "next-intl"; type GalleryContentProps = { images: string[]; }; export function GalleryContent({ images }: GalleryContentProps) { const t = useTranslations("Gallery"); 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 < images.length - 1 ? prev + 1 : prev, ); } }; // Prevent body scroll when lightbox is open document.body.style.overflow = "hidden"; window.addEventListener("keydown", handleKeyDown); return () => { document.body.style.overflow = ""; window.removeEventListener("keydown", handleKeyDown); }; }, [lightboxIndex, images.length]); const openLightbox = useCallback((index: number) => { setLightboxIndex(index); }, []); const closeLightbox = useCallback(() => { setLightboxIndex(null); }, []); if (images.length === 0) { return (
{t("empty")}
); } return ( <>
{images.map((src, index) => (
openLightbox(index)} > {`Gallery
))}
{/* Lightbox */} {lightboxIndex !== null && (
{/* Close */} {/* Previous */} {lightboxIndex > 0 && ( )} {/* Next */} {lightboxIndex < images.length - 1 && ( )} {/* Image */}
e.stopPropagation()} > {`Gallery
{/* Counter */}
{lightboxIndex + 1} / {images.length}
)} ); }