"use client"; import { Button } from "@suphark/ui/components/shared/button/button"; import { useUiText } from "@suphark/ui/components/shared/ui-text"; import { focusAfterDismiss } from "@suphark/ui/lib/focus-after-remove"; import { type Cell, flexRender, type Row } from "@tanstack/react-table"; import type { ReactNode } from "react"; import { StatusError } from "../shared/semantic-icons"; import { type DataTableEditable, DataTableEditableCell } from "./data-table-editable-cell"; /** เนื้อเซลล์: คอลัมน์ที่มี `meta.editable` ห่อด้วยตัวแก้ค่าในเซลล์ — ใช้ทั้งแถวปกติ แถวลากเรียง และรายการมือถือ */ export function renderCellContent(cell: Cell) { const content = flexRender(cell.column.columnDef.cell, cell.getContext()); const editable = ( cell.column.columnDef.meta as { editable?: DataTableEditable } | undefined )?.editable; if (!editable) return content; return ( {content} ); } const CONTROL_COLUMNS = new Set(["select", "dnd-handle", "actions"]); /** พื้นและแถบสีของแถวที่มีข้อผิดพลาด (`getRowError`) */ export const ROW_ERROR_CLASS = "bg-destructive-subtle/40 shadow-[inset_3px_0_0_var(--destructive)] hover:bg-destructive-subtle/60"; /** เซลล์ที่แสดงข้อความผิดพลาดของแถว: เซลล์เนื้อหาแรก (ข้ามช่องติ๊ก/ที่จับ/ปุ่มท้ายแถว) */ export function rowErrorCellId(row: Row): string | undefined { const cells = row.getVisibleCells(); return (cells.find((cell) => !CONTROL_COLUMNS.has(cell.column.id)) ?? cells[0])?.id; } /** * ข้อความผิดพลาดใต้เนื้อหาของแถว — อยู่ในเซลล์ ไม่ใช่แถวแยก เพื่อให้ใช้ได้ทั้งแถวลากเรียงและตารางเสมือน * กด "ลองใหม่" แล้วบรรทัดนี้หายทันที โฟกัสย้ายไปตัวถัดไป ไม่หลุดกลับต้นหน้า */ export function DataTableRowError({ row, message, onRetry, }: { row: Row; message: ReactNode; onRetry?: (row: Row) => void; }) { const text = useUiText(); return (
); }