'use client'; import Layout from '@/components/layout/Layout'; import axios from 'axios'; import Link from 'next/link'; import { useSearchParams, useRouter } from 'next/navigation'; import { useEffect, useState, useCallback } from 'react'; import Lightbox from "yet-another-react-lightbox"; import "yet-another-react-lightbox/styles.css"; interface EventImage { id: string; src: string; title?: string; description?: string; } export default function SingleGallery() { const searchParams = useSearchParams(); const eventId = searchParams.get('id'); const router = useRouter(); const [eventImages, setEventImages] = useState([]); const [open, setOpen] = useState(false); const [currentIndex, setCurrentIndex] = useState(0); const getEventGallery = useCallback(async () => { try { const res = await axios.get( `https://api.tamilculturewaterloo.org/api/event-images/event/${eventId}` ); const formatted = res.data?.data?.map((img: any) => ({ id: img.id, src: img.imageurl, title: img?.title || '', description: img?.description || '', })); setEventImages(formatted || []); } catch (error) { console.log("Error fetching event images", error); } }, [eventId]); useEffect(() => { if (eventId) { getEventGallery(); } }, [eventId, getEventGallery]); const handleImageClick = (index: number) => { setCurrentIndex(index); setOpen(true); }; return ( {/* Header Section */}

Recent Memories

Home Recent Memories
{/* Gallery Section */}

Photos Gallery

{eventImages.map((image, index) => (
handleImageClick(index)} > {image.title
))} {eventImages.length === 0 && (

No images found for this event.

)}
{/* Lightbox */} setOpen(false)} index={currentIndex} slides={eventImages.map((img) => ({ src: img.src, title: img.title }))} /> ); }