"use client"; import { Button, Card, CardFooter, CircularProgress, Image, ScrollShadow, } from "@heroui/react"; import { ChevronLeftIcon, ChevronRightIcon, EyeIcon, VideoIcon, } from "../icons"; import { Swiper, SwiperSlide, useSwiper } from "swiper/react"; import "swiper/css"; import "swiper/css/navigation"; import Link from "next/link"; import { Autoplay, Pagination, Navigation, Controller } from "swiper/modules"; import { useEffect, useRef, useState } from "react"; import { getAdvertise } from "@/services/advertisement"; import VideoPlayer from "../player/video-player"; interface Jumbotron { id: number; title: string; description: string; redirectLink: string; contentFileUrl: string; } export default function AddsCarousel() { const [jumbotronList, setJumbotronList] = useState([]); const videoRefs = useRef<(HTMLVideoElement | null)[]>([]); const [thumbnail, setThumbnail] = useState(null); const [swiperInstance, setSwiperInstance] = useState(null); const [selectedVideo, setSelectedVideo] = useState(0); useEffect(() => { initFetch(); }, []); const initFetch = async () => { const req = { page: 1, limit: 5, placement: "banner", isPublish: true }; const res = await getAdvertise(req); setJumbotronList(res?.data?.data); }; return (
{jumbotronList ? ( { setSwiperInstance(swiper); swiper.navigation.nextEl?.classList.add( "bg-white/70", "!text-black", "rounded-full", "!w-[40px]", "!h-[40px]" ); swiper.navigation.prevEl?.classList.add( "bg-white/70", "!text-black", "rounded-full", "!w-[40px]", "!h-[40px]" ); }} onSlideChange={() => { videoRefs.current.forEach((video) => { if (video && !video.paused) { video.pause(); setSelectedVideo(0); } }); }} > {jumbotronList?.map((newsItem, index) => ( {newsItem.contentFileUrl.includes(".mp4") ? ( selectedVideo === newsItem?.id ? ( { videoRefs.current[index] = el; }} url={newsItem.contentFileUrl} onPlay={() => { if (swiperInstance) swiperInstance.autoplay.stop(); }} onPause={() => { if (swiperInstance) swiperInstance.autoplay.start(); }} /> ) : ( ) ) : ( // thumbnail ? ( // selectedVideo === newsItem?.id ? ( // // ) : ( // Video thumbnail // ) // ) : ( // ))} ) : ( "" // )}
); }