"use client"; import { FC, useState } from "react"; import { FaImages } from "react-icons/fa"; import LightGallery from "lightgallery/react"; // import styles import "lightgallery/css/lightgallery.css"; import "lightgallery/css/lg-zoom.css"; import "lightgallery/css/lg-thumbnail.css"; import { Button } from "@/components/atoms/Button"; type ImageData = { aspect_ratio: number; file_path: string; height: number; width: number; }; type Props = { heading?: string; images: ImageData[] | Record; limit?: number; }; export const Gallery: FC = ({ images, heading, limit: initialLimit = 14, }) => { const categories = Array.isArray(images) ? [] : Object.keys(images); const [limit, setLimit] = useState(initialLimit); const [selectedCategory, setSelectedCategory] = useState( categories[0] || null ); const currentImages: ImageData[] = selectedCategory && typeof images === "object" ? (images[selectedCategory as keyof typeof images] as ImageData[]) : (images as ImageData[]); const getImageUrl = (path: string, size: string = "w500") => { return `https://image.tmdb.org/t/p/${size}${path}`; }; return (
{heading && (

{heading}

)} {/* Category tabs */} {categories.length > 0 && (
{Object.entries(images).map(([category, categoryImages]) => { if (!categoryImages.length) return null; return ( ); })}
)} {/* Image grid */}
div]:contents`}> {currentImages.slice(0, limit).map((image, index) => ( ))}
{limit < currentImages.length && (
)}
); };