"use client"; import { useEffect, useRef } from "react"; import { usePathname } from "next/navigation"; import ThemeSwitch from "@/components/ThemeSwitch"; const NAV = [ { href: "/", key: "nav.home", label: "หน้าแรก" }, { href: "/stops", key: "nav.stops", label: "ป้ายหยุดรถ" }, { href: "/routes", key: "nav.routes", label: "รายละเอียดสายรถ" }, { href: "/about", key: "nav.about", label: "เกี่ยวกับเรา" }, { href: "/blog", key: "nav.blog", label: "บ่นไปเรื่อย" }, { href: "/credits", key: "nav.credits", label: "เครดิต" }, ]; function isActive(pathname: string, href: string): boolean { if (href === "/") return pathname === "/"; return pathname === href || pathname.startsWith(`${href}/`); } export default function SiteHeader() { const pathname = usePathname() || "/"; const menuRef = useRef(null); // ปิดเมนู hamburger เมื่อเปลี่ยนหน้า หรือคลิกนอกเมนู (เดิมอยู่ใน index.html) useEffect(() => { if (menuRef.current) menuRef.current.removeAttribute("open"); function onDocClick(event: MouseEvent) { const menu = menuRef.current; if (!menu) return; const target = event.target as HTMLElement; if (target.closest(".mu-menu-panel a")) { menu.removeAttribute("open"); return; } if (!target.closest(".mu-menu")) menu.removeAttribute("open"); } document.addEventListener("click", onDocClick); return () => document.removeEventListener("click", onDocClick); }, [pathname]); return (
{/* eslint-disable-next-line @next/next/no-img-element */} Atroute logo Atroute สถานีขนส่งผู้โดยสารจังหวัดอ่างทอง
{NAV.slice(0, 3).map((item) => ( {item.label} ))} เช็กเวลาเดินรถ {NAV.slice(3).map((item) => ( {item.label} ))}
เช็กเวลาเดินรถ
); }