"use client" import { useState, useRef, useCallback } from "react" import Image from "next/image" import { ChevronLeft, ChevronRight } from "lucide-react" import { Button } from "@/components/ui/button" const TOTAL_SLIDES = 12 const SWIPE_THRESHOLD = 50 export default function SponsorshipFlipbook() { const [currentSlide, setCurrentSlide] = useState(0) const [isFlipping, setIsFlipping] = useState(false) const [flipDirection, setFlipDirection] = useState<"left" | "right">("left") const touchStartX = useRef(0) const touchEndX = useRef(0) const goTo = useCallback( (direction: "prev" | "next") => { if (isFlipping) return if (direction === "prev" && currentSlide === 0) return if (direction === "next" && currentSlide >= TOTAL_SLIDES - 1) return setFlipDirection(direction === "next" ? "left" : "right") setIsFlipping(true) setTimeout(() => { setCurrentSlide((s) => direction === "next" ? Math.min(TOTAL_SLIDES - 1, s + 1) : Math.max(0, s - 1) ) setIsFlipping(false) }, 400) }, [currentSlide, isFlipping] ) const handleClick = (e: React.MouseEvent) => { const rect = e.currentTarget.getBoundingClientRect() const clickX = e.clientX - rect.left if (clickX < rect.width / 2) { goTo("prev") } else { goTo("next") } } const handleTouchStart = (e: React.TouchEvent) => { touchStartX.current = e.touches[0].clientX touchEndX.current = e.touches[0].clientX } const handleTouchMove = (e: React.TouchEvent) => { touchEndX.current = e.touches[0].clientX } const handleTouchEnd = () => { const diff = touchStartX.current - touchEndX.current if (Math.abs(diff) > SWIPE_THRESHOLD) { goTo(diff > 0 ? "next" : "prev") } } return (
{`Sponsorship
{currentSlide + 1} / {TOTAL_SLIDES}
) }