"use client"; import { ScrollFades, useScrollFade } from "@suphark/ui/components/shared/scroll-fade"; import { useUiText } from "@suphark/ui/components/shared/ui-text"; import { cn } from "@suphark/ui/lib/utils"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { type AppNavGroup, type AppNavItem, isNavActive } from "./types"; /** ชั้นแรกของ nav ทุกกลุ่มรวมกันเป็นแท็บ — href ของแท็บที่ไม่มี href = ลูกตัวแรก */ export function topLevelTabs(nav: AppNavGroup[]): Array { const out: Array = []; for (const group of nav) { for (const item of group.items) { const href = item.href ?? firstHref(item.items); if (href) out.push({ ...item, href }); } } return out; } function firstHref(items?: AppNavItem[]): string | undefined { for (const i of items ?? []) { if (i.href) return i.href; const deep = firstHref(i.items); if (deep) return deep; } return undefined; } /** แท็บ active = href ตรง (prefix) หรือลูกตัวใดตัวหนึ่ง active */ export function isTabActive(pathname: string, tab: AppNavItem): boolean { if (isNavActive(pathname, tab.href, tab.exact)) return true; return (tab.items ?? []).some((c) => isTabActive(pathname, c)); } /** แท็บหลักแนวนอนใต้ header (แบบ Clerk: Overview · Users · …) — active มีเส้นใต้; จอแคบเลื่อนแนวนอน */ export function TopTabs({ nav, className }: { nav: AppNavGroup[]; className?: string }) { const text = useUiText(); const pathname = usePathname(); const tabs = topLevelTabs(nav); const { ref, edges, onScroll } = useScrollFade(); if (tabs.length === 0) return null; return (
); }