2025-07-13 07:48:15 +00:00
|
|
|
"use client";
|
2026-02-02 08:08:30 +00:00
|
|
|
|
2025-07-13 07:48:15 +00:00
|
|
|
import Image from "next/image";
|
|
|
|
|
import {
|
|
|
|
|
Carousel,
|
|
|
|
|
CarouselContent,
|
|
|
|
|
CarouselItem,
|
|
|
|
|
CarouselNext,
|
|
|
|
|
CarouselPrevious,
|
|
|
|
|
} from "@/components/ui/carousel";
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import { motion } from "framer-motion";
|
|
|
|
|
import Link from "next/link";
|
|
|
|
|
import {
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogContent,
|
|
|
|
|
DialogHeader,
|
|
|
|
|
DialogTitle,
|
|
|
|
|
DialogTrigger,
|
|
|
|
|
} from "../ui/dialog";
|
|
|
|
|
import { Input } from "../ui/input";
|
|
|
|
|
import { Textarea } from "../ui/textarea";
|
2026-02-02 08:08:30 +00:00
|
|
|
import { useEffect, useState } from "react";
|
2025-07-13 07:48:15 +00:00
|
|
|
import Autoplay from "embla-carousel-autoplay"; // ✅ Import plugin autoplay
|
|
|
|
|
import { useRef } from "react";
|
2026-02-02 08:08:30 +00:00
|
|
|
import { getBannerData } from "@/service/banner";
|
2025-07-13 07:48:15 +00:00
|
|
|
|
2026-02-02 08:08:30 +00:00
|
|
|
const heroImages = [
|
|
|
|
|
"/Hero.png",
|
|
|
|
|
// "/Carousell-01.png",
|
|
|
|
|
"/Carousell-02.png",
|
|
|
|
|
"/Carousell-03.png",
|
|
|
|
|
"/Carousell-04.png",
|
|
|
|
|
"/Carousell-05.png",
|
|
|
|
|
];
|
|
|
|
|
type Banner = {
|
|
|
|
|
id: number;
|
|
|
|
|
title: string;
|
|
|
|
|
description: string;
|
|
|
|
|
status_id: number;
|
|
|
|
|
position: string;
|
|
|
|
|
thumbnail_url: string;
|
|
|
|
|
created_at: string;
|
|
|
|
|
};
|
2025-07-13 07:48:15 +00:00
|
|
|
|
|
|
|
|
export default function Header() {
|
|
|
|
|
const [open, setOpen] = useState(false);
|
2026-02-02 08:08:30 +00:00
|
|
|
const [banners, setBanners] = useState<Banner[]>([]);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const fetchBanners = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const req = {
|
|
|
|
|
limit: "10",
|
|
|
|
|
page: 1,
|
|
|
|
|
search: "",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const res = await getBannerData(req);
|
|
|
|
|
|
|
|
|
|
const bannerData: Banner[] = res?.data?.data || [];
|
|
|
|
|
|
|
|
|
|
const activeBanners = bannerData
|
|
|
|
|
.filter((banner) => banner.status_id === 2) // ✅ approved only
|
|
|
|
|
.sort((a, b) => {
|
|
|
|
|
const posA = Number(a.position);
|
|
|
|
|
const posB = Number(b.position);
|
|
|
|
|
|
|
|
|
|
if (posA !== posB) return posA - posB;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
new Date(b.created_at).getTime() -
|
|
|
|
|
new Date(a.created_at).getTime()
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
setBanners(activeBanners);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error("Failed to fetch banners:", err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
fetchBanners();
|
|
|
|
|
}, []);
|
2025-07-13 07:48:15 +00:00
|
|
|
|
|
|
|
|
const plugin = useRef(Autoplay({ delay: 4000, stopOnInteraction: false }));
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<section className="relative w-full overflow-hidden bg-white">
|
2026-02-02 08:08:30 +00:00
|
|
|
<Carousel className="w-full relative" plugins={[plugin.current]}>
|
2025-07-13 07:48:15 +00:00
|
|
|
<CarouselContent>
|
2026-02-02 08:08:30 +00:00
|
|
|
{banners.map((banner, index) => (
|
|
|
|
|
<CarouselItem key={banner.id}>
|
2025-07-13 11:27:37 +00:00
|
|
|
<div className="relative w-full h-[400px] sm:h-[500px] md:h-[810px]">
|
2025-07-13 07:48:15 +00:00
|
|
|
<Image
|
2026-02-02 08:08:30 +00:00
|
|
|
src={banner.thumbnail_url}
|
|
|
|
|
alt={banner.title}
|
|
|
|
|
fill
|
|
|
|
|
priority={index === 0}
|
|
|
|
|
className="object-cover"
|
2025-07-13 07:48:15 +00:00
|
|
|
/>
|
|
|
|
|
|
2026-02-02 08:08:30 +00:00
|
|
|
{/* {index === 0 && (
|
2025-07-13 11:27:37 +00:00
|
|
|
<div className="absolute inset-0 flex flex-col justify-center items-start px-4 sm:px-8 md:px-28 z-10">
|
2025-07-13 07:48:15 +00:00
|
|
|
<motion.h1
|
|
|
|
|
initial={{ opacity: 0, y: 40 }}
|
|
|
|
|
animate={{ opacity: 1, y: 0 }}
|
2026-02-02 08:08:30 +00:00
|
|
|
transition={{ duration: 0.8 }}
|
2025-07-13 11:27:37 +00:00
|
|
|
className="text-2xl sm:text-3xl md:text-5xl font-bold text-black mb-4"
|
2025-07-13 07:48:15 +00:00
|
|
|
>
|
2026-02-02 08:08:30 +00:00
|
|
|
{banner.title}
|
2025-07-13 07:48:15 +00:00
|
|
|
</motion.h1>
|
|
|
|
|
|
2026-02-02 08:08:30 +00:00
|
|
|
{banner.description && (
|
|
|
|
|
<motion.p
|
2025-07-13 11:27:37 +00:00
|
|
|
initial={{ opacity: 0, y: 40 }}
|
|
|
|
|
animate={{ opacity: 1, y: 0 }}
|
2026-02-02 08:08:30 +00:00
|
|
|
transition={{ duration: 0.9, delay: 0.2 }}
|
|
|
|
|
className="text-sm sm:text-base md:text-lg text-black mb-6"
|
2025-07-13 11:27:37 +00:00
|
|
|
>
|
2026-02-02 08:08:30 +00:00
|
|
|
{banner.description}
|
|
|
|
|
</motion.p>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
2025-07-13 07:48:15 +00:00
|
|
|
</div>
|
2026-02-02 08:08:30 +00:00
|
|
|
)} */}
|
2025-07-13 07:48:15 +00:00
|
|
|
</div>
|
|
|
|
|
</CarouselItem>
|
|
|
|
|
))}
|
|
|
|
|
</CarouselContent>
|
|
|
|
|
</Carousel>
|
|
|
|
|
</section>
|
|
|
|
|
);
|
|
|
|
|
}
|