2025-02-24 12:24:58 +00:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import Image from "next/image";
|
|
|
|
|
import {
|
|
|
|
|
Button,
|
|
|
|
|
Card,
|
|
|
|
|
CardFooter,
|
|
|
|
|
CircularProgress,
|
|
|
|
|
ScrollShadow,
|
|
|
|
|
} from "@heroui/react";
|
|
|
|
|
import { ChevronLeftIcon, ChevronRightIcon, EyeIcon } 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";
|
2025-03-11 10:19:37 +00:00
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
|
import { getAdvertise } from "@/service/advertisement";
|
|
|
|
|
|
2025-02-24 12:24:58 +00:00
|
|
|
const datas = [
|
2025-03-11 10:19:37 +00:00
|
|
|
{ id: 1, src: "/sample-banner.png" },
|
|
|
|
|
{ id: 2, src: "/sample-banner-2.png" },
|
|
|
|
|
{ id: 2, src: "/sample-banner-3.jpg" },
|
2025-02-24 12:24:58 +00:00
|
|
|
];
|
2025-03-11 10:19:37 +00:00
|
|
|
|
|
|
|
|
interface Jumbotron {
|
|
|
|
|
id: number;
|
|
|
|
|
title: string;
|
|
|
|
|
description: string;
|
|
|
|
|
redirectLink: string;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-24 12:24:58 +00:00
|
|
|
export default function AddsCarousel() {
|
2025-03-11 10:19:37 +00:00
|
|
|
const [jumbotronList, setJumbotronList] = useState<Jumbotron[]>([]);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
initFetch();
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const initFetch = async () => {
|
|
|
|
|
const req = { page: 1, limit: 5, placement: "banner" };
|
|
|
|
|
const res = await getAdvertise(req);
|
|
|
|
|
setJumbotronList(res?.data?.data);
|
|
|
|
|
};
|
2025-02-24 12:24:58 +00:00
|
|
|
return (
|
2025-02-25 10:30:33 +00:00
|
|
|
<div className="w-[90%] lg:w-[75%] mx-auto">
|
2025-03-11 10:19:37 +00:00
|
|
|
{jumbotronList ? (
|
2025-02-24 12:24:58 +00:00
|
|
|
<Swiper
|
|
|
|
|
centeredSlides={true}
|
|
|
|
|
autoplay={{
|
|
|
|
|
delay: 5000,
|
|
|
|
|
disableOnInteraction: false,
|
|
|
|
|
}}
|
|
|
|
|
navigation={true}
|
|
|
|
|
modules={[Autoplay, Controller, Navigation]}
|
|
|
|
|
className="mySwiper"
|
|
|
|
|
onSwiper={(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]"
|
|
|
|
|
);
|
|
|
|
|
}}
|
|
|
|
|
>
|
2025-03-11 10:19:37 +00:00
|
|
|
{jumbotronList?.map((newsItem, index) => (
|
2025-02-25 10:30:33 +00:00
|
|
|
<SwiperSlide key={newsItem?.id} className="h-[20vh] lg:h-[50vh]">
|
2025-02-24 12:24:58 +00:00
|
|
|
<Card
|
|
|
|
|
isFooterBlurred
|
|
|
|
|
radius="lg"
|
2025-02-25 10:30:33 +00:00
|
|
|
className="border-none h-[20vh] lg:h-[50vh] shadow-none"
|
2025-02-24 12:24:58 +00:00
|
|
|
>
|
|
|
|
|
<Image
|
|
|
|
|
alt="headernews"
|
|
|
|
|
width={1440}
|
|
|
|
|
height={1080}
|
2025-02-25 10:30:33 +00:00
|
|
|
className="w-full h-[20vh] lg:!h-[50vh] object-cover rounded-lg"
|
2025-03-11 10:19:37 +00:00
|
|
|
// src={newsItem?.src == "" ? "/no-image.jpg" : newsItem?.src}
|
|
|
|
|
src={datas[index % 3].src}
|
2025-02-24 12:24:58 +00:00
|
|
|
/>
|
|
|
|
|
</Card>
|
|
|
|
|
</SwiperSlide>
|
|
|
|
|
))}
|
|
|
|
|
</Swiper>
|
|
|
|
|
) : (
|
|
|
|
|
<CircularProgress aria-label="Loading..." size="lg" />
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|