"use client" import * as React from "react" import { type ColumnDef } from "@tanstack/react-table" import { Edit, Paperclip } from "lucide-react" import { formatCurrency, formatDate, formatDateTime } from "@/lib/utils" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { Checkbox } from "@/components/ui/checkbox" import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip" import { DataTableColumnHeader } from "@/components/data-table/data-table-column-header" import { TechSalesVendorQuotations, TECH_SALES_QUOTATION_STATUS_CONFIG } from "@/db/schema" import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime" interface QuotationWithRfqCode extends TechSalesVendorQuotations { rfqCode?: string; materialCode?: string; dueDate?: Date; rfqStatus?: string; itemName?: string; projNm?: string; quotationCode?: string | null; quotationVersion?: number | null; rejectionReason?: string | null; acceptedAt?: Date | null; attachmentCount?: number; } interface GetColumnsProps { router: AppRouterInstance; openAttachmentsSheet: (rfqId: number) => void; } export function getColumns({ router, openAttachmentsSheet }: GetColumnsProps): ColumnDef[] { return [ { id: "select", header: ({ table }) => ( table.toggleAllPageRowsSelected(!!value)} aria-label="모두 선택" className="translate-y-0.5" /> ), cell: ({ row }) => ( row.toggleSelected(!!value)} aria-label="행 선택" className="translate-y-0.5" /> ), enableSorting: false, enableHiding: false, }, { accessorKey: "id", header: ({ column }) => ( ), cell: ({ row }) => (
{row.getValue("id")}
), enableSorting: true, enableHiding: true, }, { accessorKey: "rfqCode", header: ({ column }) => ( ), cell: ({ row }) => { const rfqCode = row.getValue("rfqCode") as string; return (
{rfqCode || "N/A"}
); }, enableSorting: true, enableHiding: false, }, { accessorKey: "materialCode", header: ({ column }) => ( ), cell: ({ row }) => { const materialCode = row.getValue("materialCode") as string; return (
{materialCode || "N/A"}
); }, enableSorting: true, enableHiding: true, }, { accessorKey: "itemName", header: ({ column }) => ( ), cell: ({ row }) => { const itemName = row.getValue("itemName") as string; return (
{itemName || "N/A"}

{itemName || "N/A"}

); }, enableSorting: false, enableHiding: true, }, { accessorKey: "projNm", header: ({ column }) => ( ), cell: ({ row }) => { const projNm = row.getValue("projNm") as string; return (
{projNm || "N/A"}

{projNm || "N/A"}

); }, enableSorting: false, enableHiding: true, }, { id: "attachments", header: ({ column }) => ( ), cell: ({ row }) => { const quotation = row.original const attachmentCount = quotation.attachmentCount || 0 const handleClick = () => { openAttachmentsSheet(quotation.rfqId) } return (

{attachmentCount > 0 ? `${attachmentCount}개 첨부파일 보기` : "첨부파일 없음"}

) }, enableSorting: false, enableHiding: true, }, { accessorKey: "status", header: ({ column }) => ( ), cell: ({ row }) => { const status = row.getValue("status") as string; const statusConfig = TECH_SALES_QUOTATION_STATUS_CONFIG[status as keyof typeof TECH_SALES_QUOTATION_STATUS_CONFIG] || { label: status, variant: "secondary" as const }; return (
{statusConfig.label}
); }, enableSorting: true, enableHiding: false, filterFn: (row, id, value) => { return value.includes(row.getValue(id)); }, }, { accessorKey: "currency", header: ({ column }) => ( ), cell: ({ row }) => { const currency = row.getValue("currency") as string; return (
{currency || "N/A"}
); }, enableSorting: true, enableHiding: true, }, { accessorKey: "totalPrice", header: ({ column }) => ( ), cell: ({ row }) => { const totalPrice = row.getValue("totalPrice") as string; const currency = row.getValue("currency") as string; if (!totalPrice || totalPrice === "0") { return (
미입력
); } return (
{formatCurrency(parseFloat(totalPrice), currency || "USD")}
); }, enableSorting: true, enableHiding: true, }, { accessorKey: "validUntil", header: ({ column }) => ( ), cell: ({ row }) => { const validUntil = row.getValue("validUntil") as Date; return (
{validUntil ? formatDate(validUntil) : "N/A"}
); }, enableSorting: true, enableHiding: true, }, { accessorKey: "submittedAt", header: ({ column }) => ( ), cell: ({ row }) => { const submittedAt = row.getValue("submittedAt") as Date; return (
{submittedAt ? formatDateTime(submittedAt) : "미제출"}
); }, enableSorting: true, enableHiding: true, }, { accessorKey: "dueDate", header: ({ column }) => ( ), cell: ({ row }) => { const dueDate = row.getValue("dueDate") as Date; const isOverdue = dueDate && new Date() > new Date(dueDate); return (
{dueDate ? formatDate(dueDate) : "N/A"}
); }, enableSorting: true, enableHiding: true, }, { accessorKey: "createdAt", header: ({ column }) => ( ), cell: ({ row }) => { const createdAt = row.getValue("createdAt") as Date; return (
{createdAt ? formatDateTime(createdAt) : "N/A"}
); }, enableSorting: true, enableHiding: true, }, { accessorKey: "updatedAt", header: ({ column }) => ( ), cell: ({ row }) => { const updatedAt = row.getValue("updatedAt") as Date; return (
{updatedAt ? formatDateTime(updatedAt) : "N/A"}
); }, enableSorting: true, enableHiding: true, }, { id: "actions", header: "작업", cell: ({ row }) => { const quotation = row.original; const rfqCode = quotation.rfqCode || "N/A"; const tooltipText = `${rfqCode} 견적서 작성`; return (

{tooltipText}

); }, enableSorting: false, enableHiding: false, }, ]; }