"use client" import { AnimatePresence, motion } from "motion/react" import { useEffect, useState } from "react" import { Button as ButtonRAC } from "react-aria-components" import { useIntl } from "react-intl" import { IconButton } from "@scandic-hotels/design-system/IconButton" import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon" import Image from "@scandic-hotels/design-system/Image" import { Typography } from "@scandic-hotels/design-system/Typography" import styles from "./gallery.module.css" import type { GalleryProps } from "@/types/components/lightbox/lightbox" export default function Gallery({ images, onClose, onSelectImage, onImageClick, selectedImage, hideLabel, }: GalleryProps) { const intl = useIntl() const [animateLeft, setAnimateLeft] = useState(true) const mainImage = selectedImage || images[0] const mainImageIndex = images.findIndex((img) => img === mainImage) function getThumbImages() { const thumbs = [] for (let i = 1; i <= Math.min(5, images.length); i++) { const index = (mainImageIndex + i) % images.length thumbs.push(images[index]) } return thumbs } function handleNext() { setAnimateLeft(true) const nextIndex = (mainImageIndex + 1) % images.length onSelectImage(images[nextIndex]) } function handlePrev() { setAnimateLeft(false) const prevIndex = (mainImageIndex - 1 + images.length) % images.length onSelectImage(images[prevIndex]) } const handleKeyDown = (e: KeyboardEvent) => { if (e.key === "ArrowLeft") { handlePrev() } else if (e.key === "ArrowRight") { handleNext() } } useEffect(() => { window.addEventListener("keydown", handleKeyDown) return () => { window.removeEventListener("keydown", handleKeyDown) } }) const variants = { initial: (animateLeft: boolean) => ({ opacity: 0, x: animateLeft ? 300 : -300, }), animate: { opacity: 1, x: 0 }, exit: (animateLeft: boolean) => ({ opacity: 0, x: animateLeft ? -300 : 300, }), } return (
{/* Desktop Gallery */}

{mainImage.caption && !hideLabel && ( {mainImage.caption} )}

{mainImage.alt}
{getThumbImages().map((image, index) => ( onSelectImage(image)} aria-label={intl.formatMessage({ defaultMessage: "Open image", })} > {image.alt} ))}
{/* Mobile Gallery */}
{images.map((image, index) => ( { onSelectImage(image) onImageClick() }} > {image.alt} ))}
) }