"use client"; import Image from "next/image"; import Link from "next/link"; import { usePathname, useRouter } from "next/navigation"; import { useEffect, useState } from "react"; import { Menu, X, Home, Box, Briefcase, Newspaper, Search, Globe, LogIn, ChevronDown, Video, Music, Image as ImageIcon, FileText, } from "lucide-react"; import { fetchPublishedArticles } from "@/lib/articles-public"; const LANDING_SECTION_IDS = new Set(["products", "services"]); function scrollToSectionId(id: string) { document .getElementById(id) ?.scrollIntoView({ behavior: "smooth", block: "start" }); } export type LandingSiteNavProps = { /** GET form target for navbar search (e.g. `/news-services`). If omitted, search is display-only. */ searchFormAction?: string; searchDefaultValue?: string; searchPlaceholder?: string; /** News hub pages: “Home” → `/news-services`, plus Konten submenu in drawer */ newsHub?: boolean; }; export default function LandingSiteNav({ searchFormAction, searchDefaultValue = "", searchPlaceholder = "Search", newsHub = false, }: LandingSiteNavProps) { const pathname = usePathname(); const router = useRouter(); const [open, setOpen] = useState(false); const [openKonten, setOpenKonten] = useState(false); const [activeMenu, setActiveMenu] = useState(null); const [event, setEvent] = useState(null); const [popular, setPopular] = useState([]); useEffect(() => { const loadPopular = async () => { const res = await fetchPublishedArticles( { typeId: 1, limit: 3, page: 1, sortBy: "view_count", sort: "desc", }, { mode: "client" }, ); setPopular(res?.items ?? []); }; loadPopular(); }, []); useEffect(() => { const loadEvent = async () => { const res = await fetchPublishedArticles( { typeId: 1, limit: 1, page: 1, sortBy: "created_at", sort: "desc", }, { mode: "client" }, ); const firstItem = res?.items?.[0]; if (firstItem) { setEvent(firstItem); } }; loadEvent(); }, []); useEffect(() => { if (pathname !== "/") return; const syncFromHash = () => { const raw = window.location.hash.replace(/^#/, ""); if (!LANDING_SECTION_IDS.has(raw)) return; const el = document.getElementById(raw); if (!el) return; requestAnimationFrame(() => el.scrollIntoView({ behavior: "smooth", block: "start" }), ); }; const t = window.setTimeout(syncFromHash, 0); window.addEventListener("hashchange", syncFromHash); return () => { window.clearTimeout(t); window.removeEventListener("hashchange", syncFromHash); }; }, [pathname]); const homePath = newsHub ? "/news-services" : "/"; const goHome = () => { setOpen(false); if (pathname === homePath) { window.scrollTo({ top: 0, behavior: "smooth" }); } else { router.push(homePath); } }; function MenuItem({ icon, label, onClick, }: { icon: React.ReactNode; label: string; onClick?: () => void; }) { return (
{icon} {label}
); } const searchField = (
); return ( <> {open ? (