'use client';
import Image from 'next/image';
import * as React from 'react';
import { ImageLightbox } from '@/components/listings/image-lightbox';
import { shimmerBlurDataURL } from '@/lib/image-blur';
import type { PropertyMedia } from '@/lib/listings-api';
import { cn } from '@/lib/utils';
interface ImageGalleryProps {
media: PropertyMedia[];
className?: string;
}
export function ImageGallery({ media, className }: ImageGalleryProps) {
const images = media.filter((m) => m.type === 'image').sort((a, b) => a.order - b.order);
const [selectedIndex, setSelectedIndex] = React.useState(0);
const [lightboxOpen, setLightboxOpen] = React.useState(false);
const openLightbox = React.useCallback((index: number) => {
setSelectedIndex(index);
setLightboxOpen(true);
}, []);
if (images.length === 0) {
return (
Chưa có hình ảnh
);
}
return (
{/* Main image */}
{/* Thumbnails */}
{images.length > 1 && (
{images.map((img, index) => (
setSelectedIndex(index)}
onDoubleClick={() => openLightbox(index)}
className={cn(
'relative h-16 w-16 flex-shrink-0 overflow-hidden rounded-md border-2 transition-colors',
index === selectedIndex ? 'border-primary' : 'border-transparent opacity-70 hover:opacity-100',
)}
>
))}
)}
{/* Lightbox */}
setLightboxOpen(false)}
/>
);
}