"use client"; import Image from "next/image"; import { CalendarDays, MessageCircle, Timer } from "lucide-react"; import Link from "next/link"; import { useEffect, useState } from "react"; import { getListArticle } from "@/service/article"; import { getAdvertise } from "@/service/advertisement"; const featured = [ { id: 1, title: "Tak Perpanjang Kontrak, Megawati Hengkang dari Red Sparks", date: "11 APRIL 2025", image: "/megawati.png", }, { id: 2, title: "Polri Dinilai Sukses Kelola Arus Mudik dan Balik Lebaran 2025", date: "11 APRIL 2025", image: "/mudik.png", }, ]; const smallNews = [ { id: 3, title: "Arus Mudik dan Balik Libur Lebaran 2025 Lancar, Kerja Keras Polri Panen Apresiasi", date: "8 APRIL 2025", image: "/mudik.png", }, { id: 4, title: "1 Juta Penonton dalam Seminggu, Jumbo Pecahkan Rekor Animasi Indonesia", date: "8 APRIL 2025", image: "/jumbo.png", }, { id: 5, title: "Jalur Fungsional Tol Jakarta-Cikampek II Selatan Siap Layani Pemudik", date: "8 APRIL 2025", image: "/tol.jpg", }, { id: 6, title: "Arus Balik Diprediksi 5-6 April, Polri Imbau Pemudik Siapkan Perjalanan", date: "8 APRIL 2025", image: "/mudik.png", }, ]; const featured1 = [ { id: 1, title: "Explore the Beauty of Bali: Beaches, Culture, and More", category: "TRAVEL IDEAS", date: "August 30, 2025", image: "/summer.jpg", }, ]; const smallNews1 = [ { id: 2, title: "Top 5 Destinations for Your Summer Getaway", category: "DESTINATION", date: "August 28, 2025", image: "/blogger.jpg", }, { id: 3, title: "How to Travel Safely During the Holiday Season", category: "NEWS", date: "August 25, 2025", image: "/trip.jpg", }, ]; const posts = [ { id: 1, title: "Your Guide to Canggu’s Hottest Street: The Essential Batu Bolong", author: "Admin", date: "27 November 2024", comments: 0, excerpt: "Dropcap the popularization of the “ideal measure” has led to advice such as “Increase font size for large screens and...", image: "/guide.jpg", }, { id: 2, title: "6 Perfect places to watch the sunrise in Bali while you honeymoon", author: "Admin", date: "26 November 2024", comments: 0, excerpt: "Intro text we refine our methods of responsive web design, we’ve increasingly focused on measure and its relationship to how...", image: "/car.jpg", }, ]; const posts1 = [ { id: 1, title: "Great Surf Spots in Bali: From Beginner to Pro Surfers", author: "Admin", date: "27 November 2024", comments: 0, excerpt: "Intro text we refine our methods of responsive web design, we’ve increasingly focused on measure and its relationship to how...", image: "/tea.jpg", }, { id: 2, title: "Important things you should know for Mount Agung hiking", author: "Admin", date: "26 November 2024", comments: 0, excerpt: "Dropcap the popularization of the “ideal measure” has led to advice such as “Increase font size for large screens and...", image: "/play.png", }, ]; const popularPosts = [ { id: 1, title: "Kisah Cinta IU-Park Bo Gum di 1950-an Hadir di When Life Gives You Tangerines, Tayang 7 Maret 2025", image: "/park-go.jpg", shares: 0, }, { id: 2, title: "Temani Perjalanan Mudik Anda dengan Musik AI dari Qudo Buana Nawakara", shares: 0, }, { id: 3, title: "Bali Nightlife Guide : The most popular clubs in Kuta", shares: 0, }, { id: 4, title: "Dirumorkan Hubungan dengan Kim Ji Won, Kim Soo Hyun Langsung Klarifikasi Begini", shares: 0, }, { id: 5, title: "Carmen Idol K-Pop Asal Bali yang Resmi Debut dengan Girl Grup Baru SM Entertainment", shares: 0, }, ]; const categories = [ { id: 1, name: "DESTINATION", count: 22 }, { id: 2, name: "FOOD & DRINK", count: 8 }, { id: 3, name: "NEWS", count: 21 }, { id: 4, name: "PHOTO", count: 17 }, { id: 5, name: "TAK BERKATEGORI", count: 34 }, { id: 6, name: "TRAVEL IDEAS", count: 27 }, { id: 7, name: "VIDEO", count: 7 }, ]; type Article = { id: number; title: string; description: string; categoryName: string; createdAt: string; publishedAt: string; createdByName: string; slug: string; customCreatorName: string; thumbnailUrl: string; categories: { title: string; }[]; files: { fileUrl: string; file_alt: string; }[]; }; type Advertise = { id: number; title: string; description: string; placement: string; contentFileUrl: string; redirectLink: string; }; export default function News() { const [page, setPage] = useState(1); const [totalPage, setTotalPage] = useState(1); const [articles, setArticles] = useState([]); const [showData, setShowData] = useState("4"); // 👈 ambil 4 artikel const [search, setSearch] = useState(""); const [selectedCategories, setSelectedCategories] = useState([]); const [startDateValue, setStartDateValue] = useState({ startDate: null, endDate: null, }); const [bannerAd, setBannerAd] = useState(null); const [bannerImageAd, setBannerImageAd] = useState(null); useEffect(() => { initStateAdver(); }, []); async function initStateAdver() { const req = { limit: 100, page: 1, sort: "desc", sortBy: "created_at", isPublish: true, }; try { const res = await getAdvertise(req); const data: Advertise[] = res?.data?.data || []; // ambil iklan placement jumbotron const jumbotron = data.find((ad) => ad.placement === "jumbotron"); if (jumbotron) setBannerAd(jumbotron); // ambil iklan placement banner const banner = data.find((ad) => ad.placement === "banner"); if (banner) setBannerImageAd(banner); } catch (err) { console.error("Error fetching advertisement:", err); } } useEffect(() => { initState(); }, [page, showData, startDateValue, selectedCategories]); async function initState() { const req = { limit: showData, page, search, categorySlug: Array.from(selectedCategories).join(","), sort: "desc", isPublish: true, sortBy: "created_at", }; try { const res = await getListArticle(req); setArticles(res?.data?.data || []); setTotalPage(res?.data?.meta?.totalPage || 1); } catch (err) { console.error("Error fetching articles:", err); } } return (
{/* Left Column */}
{/* Section Title */}

Travel Ideas

ALL NEWS TRAVEL IDEAS DESTINATION PHOTO
{/* Featured News */}
{articles.slice(0, 2).map((item) => (
{item.title}

{item.title}

{new Date(item.publishedAt).toLocaleDateString("id-ID", { day: "2-digit", month: "long", year: "numeric", })}
))}
{/* Small News */}
{articles.map((item) => (
{item.title}

{item.title}

{" "} {new Date(item.publishedAt).toLocaleDateString("id-ID", { day: "2-digit", month: "long", year: "numeric", })}
))}
{bannerImageAd ? ( {bannerImageAd.title ) : ( Banner Default )}
{/* Header */}

Travel Destination

ALL NEWS TRAVEL IDEAS DESTINATION VIDEO
{/* Featured News */}
{/* Featured News Besar */}
{articles.length > 0 && ( <> {articles[0]?.title
{articles[0]?.categories?.[0]?.title || "TAK BERKATEGORI"}

{articles[0]?.title}

BY {articles[0]?.createdByName || "ADMIN"} {new Date( articles[0]?.publishedAt || "" ).toLocaleDateString("id-ID", { day: "2-digit", month: "long", year: "numeric", })}
)}
{/* Small News */}
{articles.slice(1, 3).map((item) => (
{item.title} {/* Badge kategori di atas gambar */}
{item.categories?.[0]?.title}
{/* Content di bawah gambar */}

{item.title}

BY ADMIN {new Date(item?.publishedAt || "").toLocaleDateString( "id-ID", { day: "2-digit", month: "long", year: "numeric", } )}
))}
{bannerImageAd ? ( {bannerImageAd.title ) : ( Banner Default )}

Travel Destination

ALL NEWS TRAVEL IDEAS DESTINATION VIDEO
{/* Featured News */}
{/* Featured News Besar */}
{articles.slice(2, 4).map((post) => (
{/* Left Content */}

{post.title}

BY{" "} {post.createdByName} {new Date(post?.publishedAt || "").toLocaleDateString( "id-ID", { day: "2-digit", month: "long", year: "numeric", } )} {/* {post.comments} */}0

{post.description.split(" ").slice(0, 50).join(" ")} {post.description.split(" ").length > 50 && "..."}

{/* Right Thumbnail */}
{post.title}
))}
{bannerImageAd ? ( {bannerImageAd.title ) : ( Banner Default )}
{/* Featured News Besar */}
{articles.slice(1, 3).map((post) => (
{/* Left Content */}

{post.title}

BY{" "} {post.createdByName} {new Date(post?.publishedAt || "").toLocaleDateString( "id-ID", { day: "2-digit", month: "long", year: "numeric", } )} {/* {post.comments} */}0

{post.description.split(" ").slice(0, 50).join(" ")} {post.description.split(" ").length > 50 && "..."}

{/* Right Thumbnail */}
{post.title}
))}
{bannerImageAd ? ( {bannerImageAd.title ) : ( Banner Default )}
{/* Sidebar */}
); }