/* eslint-disable @next/next/no-img-element */ 'use client' import { Card, CardContent } from '@/components/ui-v2/card' import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui-v2/dialog' import { Carousel, type CarouselApi, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious } from '@/components/ui-v2/carousel' import { useEffect, useState } from 'react' import { PlusCircle } from 'lucide-react' interface SearchResultsImageSectionProps { images: string[] query?: string } export const SearchResultsImageSection: React.FC< SearchResultsImageSectionProps > = ({ images, query }) => { const [api, setApi] = useState() const [current, setCurrent] = useState(0) const [count, setCount] = useState(0) const [selectedIndex, setSelectedIndex] = useState(0) // Update the current and count state when the carousel api is available useEffect(() => { if (!api) { return } setCount(api.scrollSnapList().length) setCurrent(api.selectedScrollSnap() + 1) api.on('select', () => { setCurrent(api.selectedScrollSnap() + 1) }) }, [api]) // Scroll to the selected index useEffect(() => { if (api) { api.scrollTo(selectedIndex, true) } }, [api, selectedIndex]) if (!images || images.length === 0) { return
No images found
} return (
{images.slice(0, 4).map((image: any, index: number) => (
setSelectedIndex(index)} > {image ? ( {`Image ) : (
)} {index === 3 && images.length > 4 && (
)}
Search Images {query}
{images.map((img, idx) => (
{`Image
))}
Previous Next
{current} of {count}
))}
) }