import { Checkbox } from "@/components/ui/checkbox" import { Button } from "@/components/ui/button" import { Badge } from "@/components/ui/badge" import { Eye, Edit, Trash2, History } from "lucide-react" import { type ColumnDef } from "@tanstack/react-table" import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header" import { AvlListItem } from "../types" interface GetColumnsProps { selectedRows?: number[] onRowSelect?: (id: number, selected: boolean) => void } // 테이블 메타 타입 확장 declare module "@tanstack/react-table" { interface TableMeta { onCellUpdate?: (id: string, field: keyof TData, newValue: string | boolean) => Promise onCellCancel?: (id: string, field: keyof TData) => void onAction?: (action: string, data?: Partial) => void onSaveEmptyRow?: (tempId: string) => Promise onCancelEmptyRow?: (tempId: string) => void isEmptyRow?: (id: string) => boolean } } // 테이블 컬럼 정의 함수 export function getColumns({ selectedRows = [], onRowSelect }: GetColumnsProps): ColumnDef[] { const columns: ColumnDef[] = [ // 기본 정보 그룹 { header: "AVL 정보", columns: [ { id: "select", header: () =>
선택
, cell: ({ row }) => (
{ onRowSelect?.(row.original.id, !!checked) }} aria-label="행 선택" className="translate-y-[2px]" />
), enableSorting: false, enableHiding: false, size: 40, }, { accessorKey: "no", header: ({ column }) => ( ), cell: ({ getValue }) =>
{getValue() as number}
, size: 60, }, { accessorKey: "isTemplate", header: ({ column }) => ( ), cell: ({ getValue }) => { const value = getValue() as boolean return (
{value ? "표준 AVL" : "프로젝트 AVL"}
) }, size: 120, }, { accessorKey: "constructionSector", header: ({ column }) => ( ), cell: ({ getValue }) => { const value = getValue() as string return (
{value}
) }, size: 100, }, { accessorKey: "projectCode", header: ({ column }) => ( ), cell: ({ getValue }) => { const value = getValue() as string return (
{value}
) }, size: 140, }, { accessorKey: "shipType", header: ({ column }) => ( ), cell: ({ getValue }) => { const value = getValue() as string return (
{value}
) }, size: 100, }, { accessorKey: "avlKind", header: ({ column }) => ( ), cell: ({ getValue }) => { const value = getValue() as string return (
{value}
) }, size: 120, }, { accessorKey: "htDivision", header: ({ column }) => ( ), cell: ({ getValue }) => { const value = getValue() as string return (
{value}
) }, size: 80, }, { accessorKey: "rev", header: ({ column }) => ( ), cell: ({ getValue, row, table }) => { const value = getValue() as number return (
{value || 1}
) }, size: 100, }, ], }, // 집계 그룹 { header: "등록정보", columns: [ { accessorKey: "PKG", header: ({ column }) => ( ), }, { accessorKey: "materialGroup", header: ({ column }) => ( ), }, { accessorKey: "vendor", header: ({ column }) => ( ), }, { accessorKey: "Tier", header: ({ column }) => ( ), }, { accessorKey: "ownerSuggestion", header: ({ column }) => ( ), }, { accessorKey: "shiSuggestion", header: ({ column }) => ( ), }, ], }, // 등록 정보 그룹 { header: "작성정보", columns: [ { accessorKey: "createdAt", header: ({ column }) => ( ), cell: ({ getValue }) => { const date = getValue() as string return
{date}
}, size: 100, }, { accessorKey: "createdBy", header: ({ column }) => ( ), cell: ({ getValue }) => { const date = getValue() as string return
{date}
}, size: 100, }, { accessorKey: "updatedAt", header: ({ column }) => ( ), cell: ({ getValue }) => { const date = getValue() as string return
{date}
}, size: 100, }, { accessorKey: "updatedBy", header: ({ column }) => ( ), cell: ({ getValue }) => { const date = getValue() as string return
{date}
}, size: 100, }, ], }, // 액션 그룹 { id: "actions", header: "액션", columns: [ { id: "actions", header: () =>
액션
, cell: ({ row, table }) => { const isEmptyRow = table.options.meta?.isEmptyRow?.(row.id) || false if (isEmptyRow) { return (
) } return (
) }, enableSorting: false, enableHiding: false, size: 120, }, ], }, ] return columns }