"use client" import * as React from "react" import { type DataTableRowAction } from "@/types/table" import { type ColumnDef } from "@tanstack/react-table" import { formatDateTime } from "@/lib/utils" import { Badge } from "@/components/ui/badge" import { Checkbox } from "@/components/ui/checkbox" import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header" import { Button } from "@/components/ui/button" import { MoreHorizontal, Eye, FileText, Calendar } from "lucide-react" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" import { useRouter } from "next/navigation" import { BasicContractTemplateStatsView } from "@/db/schema" type NextRouter = ReturnType; interface GetColumnsProps { setRowAction: React.Dispatch | null>> router: NextRouter; } /** * BasicContractTemplateStatsView용 컬럼 정의 */ export function getColumns({ setRowAction, router }: 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" /> ), maxSize: 30, enableSorting: false, enableHiding: false, } // ---------------------------------------------------------------- // 2) Actions 컬럼 // ---------------------------------------------------------------- const actionsColumn: ColumnDef = { id: "actions", header: "작업", cell: ({ row }) => { const template = row.original const detailUrl = `/evcp/basic-contract/${template.templateId}`; return ( router.push(detailUrl)}> 상세 보기 setRowAction({ type: "view", row })}> 템플릿 보기 ) }, enableSorting: false, enableHiding: false, maxSize: 80, } // ---------------------------------------------------------------- // 3) 기본 정보 컬럼들 // ---------------------------------------------------------------- const basicInfoColumns: ColumnDef[] = [ { accessorKey: "templateName", header: ({ column }) => ( ), cell: ({ row }) => { const name = row.getValue("templateName") as string return (
{name}
) }, minSize: 200, }, { accessorKey: "revision", header: ({ column }) => ( ), cell: ({ row }) => { const revision = row.getValue("revision") as number return ( v{revision} ) }, minSize: 80, }, ] // ---------------------------------------------------------------- // 4) 발송/처리 현황 컬럼들 // ---------------------------------------------------------------- const processStatusColumns: ColumnDef[] = [ { accessorKey: "totalSentCount", header: ({ column }) => ( ), cell: ({ row }) => { const count = row.getValue("totalSentCount") as number return (
{count.toLocaleString()}
) }, minSize: 100, }, { accessorKey: "overdueCount", header: ({ column }) => ( ), cell: ({ row }) => { const count = row.getValue("overdueCount") as number const total = row.getValue("totalSentCount") as number const isHigh = total > 0 && (count / total) > 0.2 return (
{count.toLocaleString()}
) }, minSize: 100, }, { accessorKey: "unsignedCount", header: ({ column }) => ( ), cell: ({ row }) => { const count = row.getValue("unsignedCount") as number return (
{count.toLocaleString()}
) }, minSize: 120, }, ] // ---------------------------------------------------------------- // 5) 법무검토 현황 컬럼들 // ---------------------------------------------------------------- const legalReviewColumns: ColumnDef[] = [ { accessorKey: "legalRequestCount", header: ({ column }) => ( ), cell: ({ row }) => { const count = row.getValue("legalRequestCount") as number return (
{count.toLocaleString()}
) }, minSize: 100, }, { accessorKey: "legalCompletedCount", header: ({ column }) => ( ), cell: ({ row }) => { const count = row.getValue("legalCompletedCount") as number return (
{count.toLocaleString()}
) }, minSize: 100, }, { accessorKey: "contractCompletedCount", header: ({ column }) => ( ), cell: ({ row }) => { const count = row.getValue("contractCompletedCount") as number return (
{count.toLocaleString()}
) }, minSize: 100, }, ] // ---------------------------------------------------------------- // 6) 성과 지표 컬럼들 // ---------------------------------------------------------------- const performanceColumns: ColumnDef[] = [ { accessorKey: "avgProcessingDays", header: ({ column }) => ( ), cell: ({ row }) => { const days = row.getValue("avgProcessingDays") as number | null if (!days) return "-" const rounded = Math.round(days * 10) / 10 const isGood = rounded <= 5 const isWarning = rounded > 5 && rounded <= 10 let colorClass = "text-gray-900" if (isGood) colorClass = "text-green-600" else if (isWarning) colorClass = "text-orange-600" else colorClass = "text-red-600" return (
{rounded}일
) }, minSize: 100, }, ] // ---------------------------------------------------------------- // 7) 시간 정보 컬럼들 // ---------------------------------------------------------------- const timeInfoColumns: ColumnDef[] = [ { accessorKey: "templateCreatedAt", header: ({ column }) => ( ), cell: ({ row }) => { const date = row.getValue("templateCreatedAt") as Date return formatDateTime(date, "KR") }, minSize: 120, }, { accessorKey: "lastActivityDate", header: ({ column }) => ( ), cell: ({ row }) => { const date = row.getValue("lastActivityDate") as Date | null return date ? formatDateTime(date, "KR") : "-" }, minSize: 120, }, ] // ---------------------------------------------------------------- // 8) 최종 컬럼 배열 (평면 구조) // ---------------------------------------------------------------- return [ selectColumn, ...basicInfoColumns, ...processStatusColumns, ...legalReviewColumns, ...performanceColumns, ...timeInfoColumns, actionsColumn, ] }