"use client"; import { getListArticle } from "@/service/article"; import Image from "next/image"; import Link from "next/link"; import { useEffect, useState } from "react"; type Article = { id: number; title: string; description: string; categoryName: string; createdAt: string; slug: string; createdByName: string; publishedAt: string; customCreatorName: string; thumbnailUrl: string; categories: { title: string }[]; files: { fileUrl: string; file_alt: string }[]; }; export default function Header() { const [articles, setArticles] = useState([]); useEffect(() => { const fetchArticles = async () => { const req = { limit: "10", page: 1, search: "", categorySlug: "", sort: "desc", isPublish: true, sortBy: "created_at", }; const res = await getListArticle(req); setArticles(res?.data?.data || []); console.log("data slider", res?.data?.data || []); }; fetchArticles(); }, []); const flashArticles = articles.slice(0, 8); const mainArticle = articles[8] || articles[0]; const recentPosts = articles.slice(1, 5); return (
{/* FLASH STRIP */}

Flash

LOAD MORE ➜
{flashArticles.map((item) => (
{item.title}
{/* dark overlay with text */}

{item.title}

{item.categoryName || item.categories?.[0]?.title || "Berita"}
{/* play icon */}
))}
{/* Main Layout */}
{/* LEFT SIDE – MAIN ARTICLE */} {mainArticle ? (
{mainArticle.files?.[0]?.file_alt {/* White Card Overlay */}
{mainArticle.categoryName || mainArticle.categories?.[0]?.title || "Berita"}

{mainArticle.title}

By{" "} {mainArticle.customCreatorName || mainArticle.createdByName || "Admin"} {new Date( mainArticle?.publishedAt ?? mainArticle?.createdAt, ) .toLocaleString("id-ID", { day: "numeric", month: "long", year: "numeric", hour: "2-digit", minute: "2-digit", hour12: false, timeZone: "Asia/Jakarta", }) .replace("pukul ", "")}{" "} WIB
) : (

Loading...

)} {/* RIGHT SIDE – RECENT POSTS */}

Recent Posts

{recentPosts.map((item) => (
{item.title}

{item.title}

{new Date(item?.publishedAt ?? item?.createdAt) .toLocaleString("id-ID", { day: "numeric", month: "long", year: "numeric", hour: "2-digit", minute: "2-digit", hour12: false, timeZone: "Asia/Jakarta", }) .replace("pukul ", "")}{" "} WIB
))}
{/* LOAD MORE */}
{/* KOLOM PPS BOTTOM BANNER */}
Kolom PPS Bottom Banner
); }