"use client" import * as React from "react" import { type ColumnDef } from "@tanstack/react-table" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { Eye, Calendar, FileText, DollarSign, TrendingUp, TrendingDown, MoreHorizontal } from "lucide-react" import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header" import { biddingStatusLabels, contractTypeLabels, } from "@/db/schema" import { formatDate } from "@/lib/utils" import { DataTableRowAction } from "@/types/table" type BiddingSelectionItem = { id: number biddingNumber: string originalBiddingNumber: string | null title: string status: string contractType: string prNumber: string | null submissionStartDate: Date | null submissionEndDate: Date | null bidPicName: string | null supplyPicName: string | null createdBy: string | null createdAt: Date | null updatedAt: Date | null // 입찰 결과 정보 (개찰 이후에만 의미 있음) participantCount?: number submittedCount?: number avgBidPrice?: number | null minBidPrice?: number | null maxBidPrice?: number | null targetPrice?: number | null currency?: string | null } interface GetColumnsProps { setRowAction: React.Dispatch | null>> } // 상태별 배지 색상 const getStatusBadgeVariant = (status: string) => { switch (status) { case 'bidding_opened': return 'default' case 'bidding_closed': return 'outline' case 'evaluation_of_bidding': return 'secondary' case 'vendor_selected': return 'default' default: return 'outline' } } // 금액 포맷팅 const formatCurrency = (amount: string | number | null, currency = 'KRW') => { if (!amount) return '-' const numAmount = typeof amount === 'string' ? parseFloat(amount) : amount if (isNaN(numAmount)) return '-' return new Intl.NumberFormat('ko-KR', { style: 'currency', currency: currency, minimumFractionDigits: 0, maximumFractionDigits: 0, }).format(numAmount) } export function getBiddingsSelectionColumns({ setRowAction }: GetColumnsProps): ColumnDef[] { return [ // ░░░ 입찰번호 ░░░ { accessorKey: "biddingNumber", header: ({ column }) => , cell: ({ row }) => (
{row.original.biddingNumber}
), size: 120, meta: { excelHeader: "입찰번호" }, }, // ░░░ 입찰명 ░░░ { accessorKey: "title", header: ({ column }) => , cell: ({ row }) => (
), size: 200, meta: { excelHeader: "입찰명" }, }, // ░░░ 원입찰번호 ░░░ { accessorKey: "originalBiddingNumber", header: ({ column }) => , cell: ({ row }) => (
{row.original.originalBiddingNumber || '-'}
), size: 120, meta: { excelHeader: "원입찰번호" }, }, // ░░░ 진행상태 ░░░ { accessorKey: "status", header: ({ column }) => , cell: ({ row }) => ( {biddingStatusLabels[row.original.status]} ), size: 120, meta: { excelHeader: "진행상태" }, }, // ░░░ 계약구분 ░░░ { accessorKey: "contractType", header: ({ column }) => , cell: ({ row }) => ( {contractTypeLabels[row.original.contractType]} ), size: 100, meta: { excelHeader: "계약구분" }, }, // ░░░ 입찰제출기간 ░░░ { id: "submissionPeriod", header: ({ column }) => , cell: ({ row }) => { const startDate = row.original.submissionStartDate const endDate = row.original.submissionEndDate if (!startDate || !endDate) return - const now = new Date() const isPast = now > new Date(endDate) const isClosed = isPast return (
{formatDate(startDate, "KR")} ~ {formatDate(endDate, "KR")}
{isClosed && ( 마감 )}
) }, size: 140, meta: { excelHeader: "입찰제출기간" }, }, // ░░░ 입찰담당자 ░░░ { accessorKey: "bidPicName", header: ({ column }) => , cell: ({ row }) => { const bidPic = row.original.bidPicName const supplyPic = row.original.supplyPicName const displayName = bidPic || supplyPic || "-" return {displayName} }, size: 100, meta: { excelHeader: "입찰담당자" }, }, // ░░░ P/R번호 ░░░ { accessorKey: "prNumber", header: ({ column }) => , cell: ({ row }) => ( {row.original.prNumber || '-'} ), size: 100, meta: { excelHeader: "P/R번호" }, }, // ░░░ 참여업체수 ░░░ { id: "participantCount", header: ({ column }) => , cell: ({ row }) => { const count = row.original.participantCount || 0 return (
{count}
) }, size: 100, meta: { excelHeader: "참여업체수" }, }, // ═══════════════════════════════════════════════════════════════ // 액션 // ═══════════════════════════════════════════════════════════════ { id: "actions", header: "작업", cell: ({ row }) => ( setRowAction({ row, type: "view" })}> 상세보기 {/* {row.original.status === 'bidding_opened' && ( <> setRowAction({ row, type: "close_bidding" })}> 입찰마감 )} */} {row.original.status === 'bidding_closed' && ( <> setRowAction({ row, type: "evaluate_bidding" })}> 평가하기 )} ), size: 50, enableSorting: false, enableHiding: false, }, ] }