"use client"; import { Button } from "@suphark/ui/components/shared/button/button"; import { useUiText } from "@suphark/ui/components/shared/ui-text"; import { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@suphark/ui/components/ui/dropdown-menu"; import type { Column, Table } from "@tanstack/react-table"; // ui-audit-ok: ปุ่ม "มุมมอง" (ปรับคอลัมน์) ไม่ใช่ "ตั้งค่า" — แถบเลื่อนแบบ shadcn data-table import { Settings2 } from "lucide-react"; /** * ชื่อในเมนู: `meta.label` → หัวคอลัมน์ที่เป็นข้อความ → id แยกคำตามตัวพิมพ์ใหญ่ * (ไม่ augment ColumnMeta ของ tanstack — ถ้าประกาศ key จะทำให้ meta ที่มี key อื่นของแอป type error) */ function columnName(column: Column): string { const { meta, header } = column.columnDef; const label = (meta as { label?: unknown } | undefined)?.label; if (typeof label === "string" && label.trim() !== "") return label; if (typeof header === "string" && header.trim() !== "") return header; return column.id.replace(/([A-Z])/g, " $1"); } interface DataTableViewOptionsProps { table: Table; /** ปุ่มไอคอนล้วน (`variant="quiet"`) */ iconOnly?: boolean; } export function DataTableViewOptions({ table, iconOnly = false, }: DataTableViewOptionsProps) { const text = useUiText().table; const columnsLabel = text?.columns ?? "คอลัมน์"; return ( ) : (