"use client" import * as React from "react" import { type ColumnDef } from "@tanstack/react-table" import { ArrowUpDown, Copy, MoreHorizontal, Edit, Trash, Eye } from "lucide-react" import Link from "next/link" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { Checkbox } from "@/components/ui/checkbox" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" import { toast } from "sonner" import { formatDate } from "@/lib/utils" import { type TemplateListView } from "@/db/schema" import { type DataTableRowAction } from "@/types/table" import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header" import { getCategoryDisplayName, getCategoryVariant } 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" /> ), enableSorting: false, enableHiding: false, }, // 템플릿 이름 컬럼 (클릭 시 세부 페이지로) { accessorKey: "name", header: ({ column }) => ( ), cell: ({ row }) => { const template = row.original return (
{template.name} {template.description && (
{template.description}
)}
) }, enableSorting: true, enableHiding: false, size:200 }, { accessorKey: "subject", header: ({ column }) => ( ), cell: ({ getValue }) => { const subject = getValue() as string return (
{subject}
) }, enableSorting: true, size:250 }, // Slug 컬럼 { accessorKey: "slug", header: ({ column }) => ( ), cell: ({ getValue }) => { const slug = getValue() as string return (
{slug}
) }, enableSorting: true, size:120 }, // 카테고리 컬럼 { accessorKey: "category", header: ({ column }) => ( ), cell: ({ row }) => { const category = row.original.category const displayName = getCategoryDisplayName(category) const variant = getCategoryVariant(category) return ( {displayName} ) }, enableSorting: true, filterFn: (row, id, value) => { return value.includes(row.getValue(id)) }, size:120 }, // 변수 개수 컬럼 { accessorKey: "variableCount", header: ({ column }) => ( ), cell: ({ row }) => { const variableCount = row.original.variableCount const requiredCount = row.original.requiredVariableCount return (
{variableCount}
{requiredCount > 0 && (
필수: {requiredCount}
)}
) }, enableSorting: true, size:80 }, // 버전 컬럼 { accessorKey: "version", header: ({ column }) => ( ), cell: ({ getValue }) => { const version = getValue() as number return (
v{version}
) }, enableSorting: true, size:80 }, // 생성일 컬럼 { accessorKey: "createdAt", header: ({ column }) => ( ), cell: ({ cell }) => { const date = cell.getValue() as Date return (
{formatDate(date)}
) }, enableSorting: true, size:200 }, // 수정일 컬럼 { accessorKey: "updatedAt", header: ({ column }) => ( ), cell: ({ cell }) => { const date = cell.getValue() as Date return (
{formatDate(date)}
) }, enableSorting: true, size:200 }, // Actions 컬럼 { id: "actions", cell: ({ row }) => { const template = row.original return ( {/* { setRowAction({ type: "update", row }) }} > */} { setRowAction({ type: "duplicate", row }) }} > { setRowAction({ type: "delete", row }) }} className="text-destructive focus:text-destructive" > ) }, enableSorting: false, enableHiding: false, size:80 }, ] }