/** ดัชนีค้นหาของ showcase — หัวข้อ → แท็บ + anchor (id ของ section) + คำค้นเพิ่ม */ export interface SearchEntry { title: string; tab: string; anchor?: string; keywords: string[]; } export const SEARCH_INDEX: SearchEntry[] = [ { title: "Semantic color tokens", tab: "foundations", anchor: "tokens-color", keywords: ["สี", "token", "background", "primary", "destructive", "success", "warning", "muted"], }, { title: "Sidebar & chart tokens", tab: "foundations", anchor: "tokens-sidebar-chart", keywords: ["sidebar", "chart", "กราฟ", "สี"], }, { title: "Typography scale", tab: "foundations", anchor: "tokens-typography", keywords: ["ฟอนต์", "font", "text-xs", "text-sm", "ขนาดตัวอักษร", "noto sans thai"], }, { title: "Spacing, radius & keyboard", tab: "foundations", anchor: "tokens-spacing", keywords: ["gap", "spacing", "radius", "ระยะห่าง", "layout", "keyboard", "focus"], }, { title: "Button variants & sizes", tab: "primitives", anchor: "primitives-button", keywords: ["ปุ่ม", "button", "variant", "icon button", "loading", "spinner"], }, { title: "Standard action buttons (Save / Cancel / Delete)", tab: "primitives", anchor: "primitives-shared-buttons", keywords: ["savebutton", "cancelbutton", "deletebutton", "addnewbutton", "บันทึก", "ยกเลิก", "ลบ"], }, { title: "Badge & StatusBadge", tab: "primitives", anchor: "primitives-badge", keywords: ["badge", "status", "สถานะ", "ป้าย", "tone"], }, { title: "Card, Avatar & Initials", tab: "primitives", anchor: "primitives-card", keywords: ["card", "avatar", "initials", "การ์ด", "รูปโปรไฟล์"], }, { title: "Accordion & Collapsible", tab: "primitives", anchor: "primitives-accordion", keywords: ["accordion", "collapsible", "พับ", "กาง"], }, { title: "Form fields (FieldGroup, Field, InputGroup)", tab: "forms", anchor: "forms-fields", keywords: [ "form", "ฟอร์ม", "input", "field", "label", "validation", "error", "select", "combobox", "checkbox", "radio", "switch", "date", "otp", "slider", "textarea", "react-hook-form", ], }, { title: "Table with loading / empty states", tab: "data-display", anchor: "data-triple-state", keywords: ["table", "ตาราง", "skeleton", "empty", "loading", "ว่าง"], }, { title: "DataTable (@suphark/ui/data-table)", tab: "data-display", anchor: "data-table", keywords: ["datatable", "tanstack", "filter", "pagination", "sort", "ตาราง", "ค้นหา"], }, { title: "Item & Attachment", tab: "data-display", anchor: "data-item-attachment", keywords: ["item", "attachment", "ไฟล์แนบ", "list"], }, { title: "Number & date formatters", tab: "data-display", anchor: "data-formatters", keywords: ["formattednumber", "relativedate", "วันที่", "ตัวเลข", "บาท", "currency"], }, { title: "Dialog, AlertDialog, Sheet & Drawer", tab: "overlays", anchor: "overlays-dialog", keywords: [ "dialog", "modal", "sheet", "drawer", "alertdialog", "ยืนยัน", "กล่องโต้ตอบ", "formdialog", ], }, { title: "Popover, Tooltip, HoverCard & menus", tab: "overlays", anchor: "overlays-popover", keywords: ["popover", "tooltip", "hovercard", "menubar", "contextmenu", "dropdown", "เมนู"], }, { title: "Breadcrumb, Pagination, Tabs & Resizable", tab: "overlays", anchor: "overlays-navigation", keywords: ["breadcrumb", "pagination", "tabs", "resizable", "navigation", "นำทาง"], }, { title: "Choosing a feedback channel", tab: "feedback", anchor: "feedback-matrix", keywords: ["feedback", "แจ้งเตือน", "alert", "toast", "inline"], }, { title: "Inline Alert", tab: "feedback", anchor: "feedback-alert", keywords: ["alert", "notice", "คำเตือน"], }, { title: "Toast (sonner)", tab: "feedback", anchor: "feedback-toast", keywords: ["toast", "sonner", "undo", "แจ้งเตือน"], }, { title: "Progress & field errors", tab: "feedback", anchor: "feedback-progress", keywords: ["progress", "spinner", "fielderror", "error", "กำลังทำงาน"], }, { title: "Web Interface Guidelines (a11y)", tab: "guidelines-recipes", anchor: "rules-a11y", keywords: [ "a11y", "accessibility", "focus", "aria", "screen reader", "keyboard", "reduced motion", ], }, { title: "UX writing", tab: "guidelines-recipes", anchor: "rules-ux-writing", keywords: ["copy", "ux writing", "ข้อความ", "active voice", "empty state"], }, { title: "Redesign safety workflow", tab: "guidelines-recipes", anchor: "rules-redesign", keywords: ["redesign", "workflow", "checklist", "ปรับปรุง"], }, { title: "Code recipes", tab: "guidelines-recipes", anchor: "rules-recipes", keywords: ["recipe", "code", "pageshell", "datatable", "fieldgroup", "ตัวอย่างโค้ด"], }, { title: "AppShell (sidebar + header)", tab: "guidelines-recipes", anchor: "rules-recipes", keywords: ["appshell", "sidebar", "shell", "layout", "เมนูข้าง", "usermenu"], }, ]; /** ค้นแบบ contains ไม่สนตัวพิมพ์ ทั้ง title และ keywords — คืนเรียงตามคะแนน (ตรง title มาก่อน) */ export function searchIndex(query: string, limit = 8): SearchEntry[] { const q = query.trim().toLowerCase(); if (!q) return []; return SEARCH_INDEX.map((e) => { const t = e.title.toLowerCase(); let score = 0; if (t.startsWith(q)) score = 3; else if (t.includes(q)) score = 2; else if (e.keywords.some((k) => k.toLowerCase().includes(q))) score = 1; return { e, score }; }) .filter((x) => x.score > 0) .sort((a, b) => b.score - a.score) .slice(0, limit) .map((x) => x.e); }