'use client' import React, { useState, useRef, useEffect, useCallback } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; export interface Video { id: number; title: string; src: string; srcLow: string; // Low quality video source description: string; } interface VideoCarouselProps { videos: Video[]; } const VideoCarousel: React.FC = ({ videos }) => { const [currentIndex, setCurrentIndex] = useState(0); const [isMobile, setIsMobile] = useState(window.innerWidth < 768); const videoRefs = useRef([]); const handleResize = useCallback(() => { setIsMobile(window.innerWidth < 768); }, []); useEffect(() => { window.addEventListener('resize', handleResize); return () => window.removeEventListener('resize', handleResize); }, [handleResize]); useEffect(() => { videoRefs.current.forEach((video, index) => { if (video) { if (index === currentIndex) { video.play(); } else { video.pause(); video.currentTime = 0; } } }); }, [currentIndex]); const nextVideo = () => { setCurrentIndex((prevIndex) => (prevIndex + 1) % videos.length); }; const prevVideo = () => { setCurrentIndex((prevIndex) => (prevIndex - 1 + videos.length) % videos.length); }; return (
{videos.map((video, index) => ( currentIndex ? '100%' : '-100%', opacity: 0, rotateY: index > currentIndex ? 45 : -45 }} animate={{ scale: index === currentIndex ? 1 : 0.8, x: index === currentIndex ? 0 : index > currentIndex ? '100%' : '-100%', opacity: index === currentIndex ? 1 : 0.3, rotateY: index === currentIndex ? 0 : index > currentIndex ? 45 : -45 }} exit={{ scale: 0.8, x: index < currentIndex ? '-100%' : '100%', opacity: 0, rotateY: index < currentIndex ? -45 : 45 }} transition={{ duration: 0.7, ease: "easeInOut" }} >
))}
{videos.map((_, index) => ( ))}
); }; export default VideoCarousel;