"use client" import { AnimatePresence, motion } from "motion/react" import { useEffect, useState } from "react" import { useIntl } from "react-intl" import Image from "../../Image" import { IconButton } from "../../IconButton" import { Typography } from "../../Typography" import { LightboxImage } from "../index" import styles from "./fullView.module.css" type FullViewProps = { image: LightboxImage onClose: () => void onNext: () => void onPrev: () => void currentIndex: number totalImages: number hideLabel?: boolean } export default function FullView({ image, onClose, onNext, onPrev, currentIndex, totalImages, hideLabel, }: FullViewProps) { const intl = useIntl() const [animateLeft, setAnimateLeft] = useState(true) function handleSwipe(offset: number) { if (offset > 30) { setAnimateLeft(false) onPrev() } if (offset < -30) { setAnimateLeft(true) onNext() } } function handleNext() { setAnimateLeft(true) onNext() } function handlePrev() { setAnimateLeft(false) onPrev() } 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, }), } as const return (
{/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */} {`${currentIndex + 1} / ${totalImages}`}
handleSwipe(info.offset.x)} >
{image.alt} {image.caption && !hideLabel ? (

{image.caption}

) : null}
) }