"use client"; import { Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, } from "@suphark/ui/components/ui/breadcrumb"; import { type ElementType, Fragment, type ReactNode } from "react"; import { useUiDefaults } from "./ui-defaults"; import { useUiText } from "./ui-text"; export interface SimpleBreadcrumbItem { label: ReactNode; /** ไม่ส่ง = ข้อความเฉย ๆ · รายการสุดท้าย = หน้าปัจจุบันเสมอ ไม่เป็นลิงก์ */ href?: string; } /** * เส้นทางหน้าจาก array (แทน Breadcrumb 6 ชิ้น) — หน้าใน `AppShell` ใช้ `HeaderBreadcrumbs` ที่สร้างจาก URL ให้เอง * `maxItems` = ยุบรายการกลางเป็น … (เก็บตัวแรกและท้าย) · ลิงก์ใช้ `linkComponent` หรือค่าของ `UiDefaultsProvider` * * */ export function SimpleBreadcrumb({ items, maxItems, linkComponent, className, }: { items: ReadonlyArray; maxItems?: number; linkComponent?: ElementType; className?: string; }) { const text = useUiText().breadcrumb; const defaultLink = useUiDefaults().linkComponent; const Link = linkComponent ?? defaultLink ?? "a"; if (items.length === 0) return null; // ตัวแรก + … + ตัวท้าย (maxItems - 1 ตัว) — น้อยกว่า 2 ไม่มีความหมาย const collapse = maxItems !== undefined && maxItems >= 2 && items.length > maxItems; const tail = collapse ? items.length - (maxItems - 1) : 1; const lastIndex = items.length - 1; return ( {items.map((item, index) => { if (collapse && index > 0 && index < tail) { return index === 1 ? ( // key ตามตำแหน่ง: ป้ายเป็น ReactNode ไม่มีค่าไม่ซ้ำให้ใช้ และรายการไม่สลับที่ // biome-ignore lint/suspicious/noArrayIndexKey: ดูด้านบน ) : null; } return ( // biome-ignore lint/suspicious/noArrayIndexKey: ดูด้านบน {index === lastIndex ? ( {item.label} ) : item.href ? ( }>{item.label} ) : ( {item.label} )} {index < lastIndex && } ); })} ); }