import { ColumnDef } from "@tanstack/react-table" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { Checkbox } from "@/components/ui/checkbox" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header" import { PcrPoData, PCR_APPROVAL_STATUS_CONFIG, PCR_CHANGE_TYPE_CONFIG } from "@/lib/pcr/types" import { MoreHorizontal, Eye, Edit, Trash2 } from "lucide-react" import type { DataTableRowAction } from "@/types/table" import { DataTableColumnHeader } from "@/components/data-table/data-table-column-header" interface GetColumnsProps { setRowAction: React.Dispatch | null>> isEvcpPage?: boolean; // EvcP 페이지인지 여부 } export function getColumns({ setRowAction, isEvcpPage = false }: GetColumnsProps): ColumnDef[] { const columns: ColumnDef[] = [ { id: "select", header: ({ table }) => ( 0} onCheckedChange={(value) => { if (value) { // 하나만 선택 가능하도록 현재 행만 선택 table.getRowModel().rows.forEach((row) => { if (row.getIsSelected()) { row.toggleSelected(false); } }); } else { // 모든 선택 해제 table.toggleAllPageRowsSelected(false); } }} aria-label="행 선택" className="translate-y-[2px]" /> ), cell: ({ row, table }) => ( { if (value) { // 다른 모든 행 선택 해제 후 현재 행만 선택 table.getRowModel().rows.forEach((r) => { if (r.id !== row.id) { r.toggleSelected(false); } }); } row.toggleSelected(!!value); }} aria-label="행 선택" className="translate-y-[2px]" /> ), enableSorting: false, enableHiding: false, }, { accessorKey: "pcrApprovalStatus", header: ({ column }) => ( ), cell: ({ row }) => { const status = row.getValue("pcrApprovalStatus") as string const config = PCR_APPROVAL_STATUS_CONFIG[status as keyof typeof PCR_APPROVAL_STATUS_CONFIG] if (!config) { return {status} } return ( {config.label} ) }, filterFn: (row, id, value) => { return value.includes(row.getValue(id)) }, }, { accessorKey: "changeType", header: ({ column }) => ( ), cell: ({ row }) => { const changeType = row.getValue("changeType") as string const config = PCR_CHANGE_TYPE_CONFIG[changeType as keyof typeof PCR_CHANGE_TYPE_CONFIG] if (!config) { return {changeType} } return ( {config.label} ) }, filterFn: (row, id, value) => { return value.includes(row.getValue(id)) }, }, { accessorKey: "poContractNumber", header: ({ column }) => ( ), cell: ({ row }) => { const value = row.getValue("poContractNumber") as string return (
{value || "-"}
) }, }, { accessorKey: "project", header: ({ column }) => ( ), cell: ({ row }) => { const value = row.getValue("project") as string return (
{value || "-"}
) }, }, { accessorKey: "pcrRequestDate", header: ({ column }) => ( ), cell: ({ row }) => { const value = row.getValue("pcrRequestDate") as Date if (!value) return "-" return (
{value.toLocaleDateString('ko-KR', { year: 'numeric', month: '2-digit', day: '2-digit' })}
) }, }, { accessorKey: "revItemNumber", header: ({ column }) => ( ), cell: ({ row }) => { const value = row.getValue("revItemNumber") as string return (
{value || "-"}
) }, }, { accessorKey: "purchaseContractManager", header: ({ column }) => ( ), cell: ({ row }) => { const value = row.getValue("purchaseContractManager") as string return (
{value || "-"}
) }, }, { accessorKey: "pcrCreator", header: ({ column }) => ( ), cell: ({ row }) => { const value = row.getValue("pcrCreator") as string return (
{value || "-"}
) }, }, { accessorKey: "poContractAmountBefore", header: ({ column }) => ( ), cell: ({ row }) => { const value = row.getValue("poContractAmountBefore") as number const currency = row.original.contractCurrency if (!value) return "-" return (
{currency} {value.toLocaleString()}
) }, }, { accessorKey: "poContractAmountAfter", header: ({ column }) => ( ), cell: ({ row }) => { const value = row.getValue("poContractAmountAfter") as number const currency = row.original.contractCurrency if (!value) return "-" return (
{currency} {value.toLocaleString()}
) }, }, { accessorKey: "contractCurrency", header: ({ column }) => ( ), cell: ({ row }) => { const value = row.getValue("contractCurrency") as string return (
{value || "-"}
) }, }, // EvcP 페이지에서만 협력업체 정보 표시 ...(isEvcpPage ? [{ accessorKey: "vendorName" as const, header: ({ column }: { column: any }) => ( ), cell: ({ row }: { row: any }) => { const vendorName = row.getValue("vendorName") as string const vendorCode = row.original.vendorCode as string const displayText = vendorName ? vendorCode ? `${vendorName} (${vendorCode})` : vendorName : "-" return (
{displayText}
) }, }] : []), { accessorKey: "details", header: ({ column }) => ( ), cell: ({ row }) => { const value = row.getValue("details") as string return (
{value || "-"}
) }, }, { accessorKey: "pcrReason", header: ({ column }) => ( ), cell: ({ row }) => { const value = row.getValue("pcrReason") as string return (
{value || "-"}
) }, }, { accessorKey: "detailsReason", header: ({ column }) => ( ), cell: ({ row }) => { const value = row.getValue("detailsReason") as string return (
{value || "-"}
) }, }, { accessorKey: "rejectionReason", header: ({ column }) => ( ), cell: ({ row }) => { const value = row.getValue("rejectionReason") as string return (
{value || "-"}
) }, }, { accessorKey: "pcrResponseDate", header: ({ column }) => ( ), cell: ({ row }) => { const value = row.getValue("pcrResponseDate") as Date if (!value) return "-" return (
{value.toLocaleDateString('ko-KR', { year: 'numeric', month: '2-digit', day: '2-digit' })}
) }, }, { accessorKey: "createdAt", header: ({ column }) => ( ), cell: ({ row }) => { const value = row.getValue("createdAt") as Date if (!value) return "-" return (
{value.toLocaleDateString('ko-KR', { year: 'numeric', month: '2-digit', day: '2-digit' })}
) }, }, { id: "actions", header: ({ column }) => ( ), cell: ({ row }) => { const pcrPo = row.original return ( 작업 setRowAction({ row, type: "update" })} > 수정 ) }, enableSorting: false, enableHiding: false, }, ] return columns }