import { NavLink } from "@suphark/ui/components/app-shell/nav-link"; import { PageHeader } from "@suphark/ui/components/shared/page-header"; import { cn } from "@suphark/ui/lib/utils"; import type { ReactNode } from "react"; import { SectionNavBar } from "./section-nav-bar"; export interface SectionNavTab { /** ลิงก์เต็ม — หรือส่ง `slug` แล้วให้ `base` ของ SectionNav ประกอบเป็น `${base}/${slug}` */ href?: string; slug?: string; label: ReactNode; /** active เฉพาะ path ตรงเป๊ะ (ค่าเริ่มต้น prefix match) */ exact?: boolean; /** ต่อท้าย label เช่น จำนวน */ badge?: ReactNode; } export interface SectionNavProps { title: ReactNode; description?: ReactNode; actions?: ReactNode; /** prefix ของ href เมื่อแท็บให้ `slug` (เช่น "/directory") */ base?: string; tabs?: ReadonlyArray; /** aria-label ของแถบแท็บ (ค่าเริ่มต้น `UiText.sectionNav.tabs` — "แท็บย่อย") */ navLabel?: string; className?: string; } function tabHref(tab: SectionNavTab, base?: string): string { if (tab.href) return tab.href; const b = (base ?? "").replace(/\/+$/, ""); return `${b}/${(tab.slug ?? "").replace(/^\/+/, "")}`; } /** * หัวหมวด + แถบแท็บย่อยใต้หัวข้อ สำหรับ layout ของหมวดที่มีหลายหน้า (directory/access/security/integrations …) * = `PageHeader` + `NavLink` แต่ละแท็บ (ไฮไลต์ตาม pathname) — ไม่มี state ใช้จาก server component ได้ * * */ export function SectionNav({ title, description, actions, base, tabs, navLabel, className, }: SectionNavProps) { return (
{tabs && tabs.length > 0 && ( {tabs.map((tab) => { const href = tabHref(tab, base); return ( {tab.label} {tab.badge != null && ( {tab.badge} )} ); })} )}
); }