"use client" import * as React from "react" import { type DataTableRowAction } from "@/types/table" import { type ColumnDef } from "@tanstack/react-table" import { Ellipsis } from "lucide-react" import { formatDate } from "@/lib/utils" import { Button } from "@/components/ui/button" import { Checkbox } from "@/components/ui/checkbox" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header" // 테이블 표시에 필요한 데이터 타입 정의 interface OffshoreTopTableItem { id: number; itemId: number; workType: "TM" | "TS" | "TE" | "TP"; itemList: string | null; subItemList: string | null; itemCode: string; itemName: string; description: string | null; createdAt: Date; updatedAt: Date; } interface GetColumnsProps { setRowAction: React.Dispatch | null>> } export function getOffshoreTopColumns({ setRowAction }: GetColumnsProps): ColumnDef[] { // ---------------------------------------------------------------- // 1) select 컬럼 (체크박스) // ---------------------------------------------------------------- const selectColumn: ColumnDef = { id: "select", header: ({ table }) => ( table.toggleAllPageRowsSelected(!!value)} aria-label="Select all" className="translate-y-0.5" /> ), cell: ({ row }) => ( row.toggleSelected(!!value)} aria-label="Select row" className="translate-y-0.5" /> ), size: 40, enableSorting: false, enableHiding: false, } // ---------------------------------------------------------------- // 2) actions 컬럼 (Dropdown 메뉴) // ---------------------------------------------------------------- const actionsColumn: ColumnDef = { id: "actions", cell: ({ row }) => ( setRowAction({ row, type: "update" })} > 수정 setRowAction({ row, type: "delete" })} className="text-destructive" > 삭제 ⌘⌫ ), size: 40, enableSorting: false, enableHiding: false, } // ---------------------------------------------------------------- // 3) 데이터 컬럼들 정의 // ---------------------------------------------------------------- const dataColumns: ColumnDef[] = [ { accessorKey: "itemCode", header: ({ column }) => ( ), cell: ({ row }) =>
{row.original.itemCode}
, enableSorting: true, enableHiding: true, meta: { excelHeader: "자재 그룹", }, }, { accessorKey: "workType", header: ({ column }) => ( ), cell: ({ row }) =>
{row.original.workType}
, enableSorting: true, enableHiding: true, meta: { excelHeader: "기능(공종)", }, }, { accessorKey: "itemList", header: ({ column }) => ( ), cell: ({ row }) =>
{row.original.itemList || "-"}
, enableSorting: true, enableHiding: true, meta: { excelHeader: "자재명", }, }, { accessorKey: "subItemList", header: ({ column }) => ( ), cell: ({ row }) =>
{row.original.subItemList || "-"}
, enableSorting: true, enableHiding: true, meta: { excelHeader: "자재명(상세)", }, }, { accessorKey: "createdAt", header: ({ column }) => ( ), cell: ({ row }) => formatDate(row.original.createdAt, "KR"), enableSorting: true, enableHiding: true, meta: { excelHeader: "생성일", }, }, { accessorKey: "updatedAt", header: ({ column }) => ( ), cell: ({ row }) => formatDate(row.original.updatedAt, "KR"), enableSorting: true, enableHiding: true, meta: { excelHeader: "수정일", }, } ] // ---------------------------------------------------------------- // 4) 최종 컬럼 배열: select, dataColumns, actions // ---------------------------------------------------------------- return [ selectColumn, ...dataColumns, actionsColumn, ] }