'use client'; import React from 'react'; import Image from 'next/image'; import { motion, AnimatePresence } from 'framer-motion'; import { Inter } from 'next/font/google'; const inter = Inter({ subsets: ['latin'], weight: '500' }); export interface Image { id: number; src: string; alt: string; description: string; } const Modal: React.FC<{ image: Image; originRect: DOMRect | null; onClose: () => void }> = ({ image, originRect, onClose }) => { const handleBackdropClick = (e: React.MouseEvent | React.TouchEvent) => { if (e.target === e.currentTarget) { onClose(); } }; const initial = { x: originRect ? originRect.left + originRect.width / 2 - window.innerWidth / 2 : 0, y: originRect ? originRect.top + originRect.height / 2 - window.innerHeight / 2 : 0, scale: originRect ? originRect.width / window.innerWidth : 0.8, }; return (
{image.alt}
); }; const ImageGallery: React.FC<{ images: Image[] }> = ({ images }) => { const [selectedImage, setSelectedImage] = React.useState(null); const [originRect, setOriginRect] = React.useState(null); const imageRefs = React.useRef>(new Map()); const isMobile = typeof window !== 'undefined' && window.innerWidth < 640; const handleImageClick = (image: Image, ref: HTMLDivElement | null) => { if (isMobile) { return; // Do nothing on mobile } if (ref) { setOriginRect(ref.getBoundingClientRect()); } setSelectedImage(image); }; return (
{images.map((image) => ( { if (el) { imageRefs.current.set(image.id, el); } else { imageRefs.current.delete(image.id); } }} className={`relative w-full h-64 group cursor-pointer overflow-hidden rounded-lg shadow-lg ${ selectedImage?.id === image.id ? 'opacity-0' : 'opacity-100' } transition-opacity duration-300`} onClick={() => handleImageClick(image, imageRefs.current.get(image.id) || null)} transition={{ duration: 0.3 }} > {image.alt}

{image.alt}

{image.description}

))}
{selectedImage && originRect && !isMobile && ( setSelectedImage(null)} /> )}
); }; export default ImageGallery;