"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 { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { Checkbox } from "@/components/ui/checkbox" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuShortcut, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header" import type { TechVendorPossibleItem } from "../validations" interface GetColumnsProps { setRowAction: React.Dispatch | null>>; } export function getColumns({ setRowAction }: GetColumnsProps): ColumnDef[] { return [ // 선택 체크박스 { 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, }, // 아이템 코드 { accessorKey: "itemCode", header: ({ column }) => ( ), cell: ({ row }) => { const itemCode = row.getValue("itemCode") as string | undefined return (
{itemCode || -}
) }, size: 150, }, // // 타입 // { // accessorKey: "techVendorType", // header: ({ column }) => ( // // ), // cell: ({ row }) => { // const techVendorType = row.getValue("techVendorType") as string | undefined // // 벤더 타입 파싱 개선 - null/undefined 안전 처리 // let types: string[] = []; // if (!techVendorType) { // types = []; // } else if (techVendorType.startsWith('[') && techVendorType.endsWith(']')) { // // JSON 배열 형태 // try { // const parsed = JSON.parse(techVendorType); // types = Array.isArray(parsed) ? parsed.filter(Boolean) : [techVendorType]; // } catch { // types = [techVendorType]; // } // } else if (techVendorType.includes(',')) { // // 콤마로 구분된 문자열 // types = techVendorType.split(',').map(t => t.trim()).filter(Boolean); // } else { // // 단일 문자열 // types = [techVendorType.trim()].filter(Boolean); // } // // 벤더 타입 정렬 - 조선 > 해양TOP > 해양HULL 순 // const typeOrder = ["조선", "해양TOP", "해양HULL"]; // types.sort((a, b) => { // const indexA = typeOrder.indexOf(a); // const indexB = typeOrder.indexOf(b); // // 정의된 순서에 있는 경우 우선순위 적용 // if (indexA !== -1 && indexB !== -1) { // return indexA - indexB; // } // return a.localeCompare(b); // }); // return ( //
// {types.length > 0 ? types.map((type, index) => ( // // {type} // // )) : ( // - // )} //
// ) // }, // size: 120, // }, // 공종 { accessorKey: "workType", header: ({ column }) => ( ), cell: ({ row }) => { const workType = row.getValue("workType") as string | null return workType ? ( {workType} ) : ( - ) }, size: 100, }, // 아이템명 { accessorKey: "itemList", header: ({ column }) => ( ), cell: ({ row }) => { const itemList = row.getValue("itemList") as string | null return (
{itemList || -}
) }, size: 300, }, // 선종 (조선용) { accessorKey: "shipTypes", header: ({ column }) => ( ), cell: ({ row }) => { const shipTypes = row.getValue("shipTypes") as string | null return shipTypes ? ( {shipTypes} ) : ( - ) }, size: 120, }, // 서브아이템 (해양용) { accessorKey: "subItemList", header: ({ column }) => ( ), cell: ({ row }) => { const subItemList = row.getValue("subItemList") as string | null return (
{subItemList || -}
) }, size: 200, }, // 등록일 { accessorKey: "createdAt", header: ({ column }) => ( ), cell: ({ row }) => { const date = row.getValue("createdAt") as Date return (
{formatDate(date, "ko-KR")}
) }, size: 120, }, // 수정일 { accessorKey: "updatedAt", header: ({ column }) => ( ), cell: ({ row }) => { const date = row.getValue("updatedAt") as Date return (
{formatDate(date, "ko-KR")}
) }, size: 120, }, // 액션 메뉴 { id: "actions", enableHiding: false, cell: function Cell({ row }) { return ( setRowAction({ row, type: "delete" })} > 삭제 ⌘⌫ ) }, size: 40, }, ] }