"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, DropdownMenuShortcut, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" import { ContactPossibleItemDetail } from "../service" import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header" interface GetColumnsProps { setRowAction: React.Dispatch | null>>; } /** * tanstack table 컬럼 정의 (중첩 헤더 버전) */ export function getColumns({ 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", enableHiding: false, cell: function Cell({ row }) { return ( setRowAction({ row, type: "delete" })} > 삭제 ⌘⌫ ) }, size: 40, } // ---------------------------------------------------------------- // 3) 일반 컬럼들을 "그룹"별로 묶어 중첩 columns 생성 // ---------------------------------------------------------------- const baseColumns: ColumnDef[] = [ // 벤더 정보 { id: "vendorInfo", header: "벤더 정보", columns: [ { accessorKey: "vendorCode", enableResizing: true, header: ({ column }) => ( ), cell: ({ row }) => row.original.vendorCode ?? "", }, { accessorKey: "vendorName", enableResizing: true, header: ({ column }) => ( ), cell: ({ row }) => row.original.vendorName ?? "", }, { accessorKey: "vendorCountry", enableResizing: true, header: ({ column }) => ( ), cell: ({ row }) => { const country = row.original.vendorCountry return country || - }, }, { accessorKey: "techVendorType", enableResizing: true, header: ({ column }) => ( ), cell: ({ row }) => { const type = row.original.techVendorType return type || - }, }, ] }, // 담당자 정보 { id: "contactInfo", header: "담당자 정보", columns: [ { accessorKey: "contactName", enableResizing: true, header: ({ column }) => ( ), cell: ({ row }) => { const contactName = row.original.contactName return contactName || - }, }, { accessorKey: "contactPosition", enableResizing: true, header: ({ column }) => ( ), cell: ({ row }) => { const position = row.original.contactPosition return position || - }, }, { accessorKey: "contactEmail", enableResizing: true, header: ({ column }) => ( ), cell: ({ row }) => { const contactEmail = row.original.contactEmail return contactEmail || - }, }, { accessorKey: "contactPhone", enableResizing: true, header: ({ column }) => ( ), cell: ({ row }) => { const contactPhone = row.original.contactPhone return contactPhone || - }, }, { accessorKey: "contactCountry", enableResizing: true, header: ({ column }) => ( ), cell: ({ row }) => { const contactCountry = row.original.contactCountry return contactCountry || - }, }, { accessorKey: "isPrimary", enableResizing: true, header: ({ column }) => ( ), cell: ({ row }) => { const isPrimary = row.original.isPrimary return isPrimary ? "예" : "아니오" }, }, ] }, // 아이템 정보 { id: "itemInfo", header: "아이템 정보", columns: [ { accessorKey: "itemCode", enableResizing: true, header: ({ column }) => ( ), cell: ({ row }) => row.original.itemCode ?? "", }, { accessorKey: "itemList", enableResizing: true, header: ({ column }) => ( ), cell: ({ row }) => row.original.itemList ?? "", }, { accessorKey: "workType", enableResizing: true, header: ({ column }) => ( ), cell: ({ row }) => row.original.workType ?? "", }, { accessorKey: "shipTypes", enableResizing: true, header: ({ column }) => ( ), cell: ({ row }) => row.original.shipTypes ?? "", }, { accessorKey: "subItemList", enableResizing: true, header: ({ column }) => ( ), cell: ({ row }) => row.original.subItemList ?? "", }, ] }, // 시스템 정보 { id: "systemInfo", header: "시스템 정보", columns: [ { accessorKey: "createdAt", enableResizing: true, header: ({ column }) => ( ), cell: ({ row }) => { const dateVal = row.getValue("createdAt") as Date return formatDate(dateVal) }, }, { accessorKey: "updatedAt", enableResizing: true, header: ({ column }) => ( ), cell: ({ row }) => { const dateVal = row.getValue("updatedAt") as Date return formatDate(dateVal) }, }, ] }, ] // ---------------------------------------------------------------- // 4) 최종 컬럼 배열: select, baseColumns, actions // ---------------------------------------------------------------- return [ selectColumn, ...baseColumns, actionsColumn, ] }