// components/landing-page/headers.tsx "use client"; import { useEffect, useState } from "react"; import Image from "next/image"; import { Calendar } from "lucide-react"; import { getListArticle } from "@/service/article"; import Link from "next/link"; type Article = { id: number; title: string; description: string; categoryName: string; slug: string; createdAt: string; createdByName: string; thumbnailUrl: string; categories: { title: string }[]; files: { fileUrl: string; file_alt: string }[]; }; export default function Header() { const [articles, setArticles] = useState([]); const [showData, setShowData] = useState("5"); useEffect(() => { fetchArticles(); }, []); async function fetchArticles() { try { const req = { limit: showData, 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); } } return (
{/* TITLE */}

STOCKS EXCHANGE

{/* GRID */}
{articles.slice(0, 2).map((article, idx) => { const imageUrl = article.thumbnailUrl || article.files?.[0]?.fileUrl || "/placeholder.png"; const category = article.categoryName || article.categories?.[0]?.title || "News"; // warna overlay berbeda tiap card biar mirip contoh const overlayColors = [ "bg-purple-900/30", // untuk artikel pertama "bg-green-900/30", // untuk artikel kedua ]; return (
{/* Background Image */} {article.title} {/* Overlay Warna */}
{/* Content */}
{category.toUpperCase()}

{article.title}

{new Date(article.createdAt).toLocaleDateString("en-GB", { day: "2-digit", month: "long", year: "numeric", })}
); })}
); }