"use client"; import React, { useEffect, useState } from "react"; import Image from "next/image"; import { getListArticle } from "@/service/article"; import Link from "next/link"; import { getAdvertise } from "@/service/advertisement"; type Article = { id: number; title: string; description: string; categoryName: string; createdAt: 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 BreakingNews() { const [articles, setArticles] = useState([]); const [popular, setPopular] = useState([]); const [bannerAd, setBannerAd] = 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 || [1]; // filter iklan dengan placement = "banner" const banner = data.find((ad) => ad.placement === "jumbotron"); if (banner) { setBannerAd(banner); } } catch (err) { console.error("Error fetching advertisement:", err); } } useEffect(() => { fetchArticles(); fetchPopular(); }, []); async function fetchArticles() { try { const req = { limit: "5", page: 1, search: "", categorySlug: "", sort: "desc", isPublish: true, sortBy: "created_at", }; const res = await getListArticle(req); setArticles(res?.data?.data || []); } catch (error) { console.error("Gagal memuat artikel:", error); } } async function fetchPopular() { try { const req = { limit: "5", page: 1, search: "", categorySlug: "", sort: "", isPublish: true, sortBy: "", }; const res = await getListArticle(req); setPopular(res?.data?.data || []); } catch (error) { console.error("Gagal memuat artikel populer:", error); } } return (
{/* Kiri - Breaking News */}
{articles.map((item) => (
{item.title}

{item.title}

By {item?.customCreatorName || item?.createdByName} •{" "} {new Date(item.createdAt).toLocaleDateString("id-ID", { day: "numeric", month: "long", year: "numeric", })}

{item.description}

))}
{/* Tengah - Browse Categories & Topics (dummy) */}

BROWSE BY CATEGORIES

  • Berita Opini
  • Berita Populer
  • Berita Terkini
  • Jaga Negeri
  • National
  • Politics
  • Ragam Nusantara

BROWSE BY TOPICS

{[ "#GIIAS2025", "#mdtranscorp", "2018 League", "Bali United", "Chopper Bike", ].map((topic, i) => ( {topic} ))}
{/* Kanan - Popular News */}

POPULAR NEWS

{popular.length > 0 && (
{/* Item pertama tampil besar */}
{
{popular[0]?.title}
01
{/* Item sisanya */}
{popular.slice(1).map((item, i) => (
0{i + 2}
{item.title}

0 Shares

))}
)} {/* Advert */}
{bannerAd ? (
{bannerAd.title
) : ( Berita Utama )}
); }