"use client" import * as React from "react" 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 { DataTableColumnHeader } from "@/components/data-table/data-table-column-header" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" import { type ApprovalLine } from "../service" import { formatApprovalLine } from "../utils/format" import { formatDate } from "@/lib/utils" import { MoreHorizontal, Copy, Edit, Trash2 } from "lucide-react" interface GetColumnsProps { setRowAction: React.Dispatch>; } export function getColumns({ setRowAction }: GetColumnsProps): ColumnDef[] { return [ { id: "select", header: ({ table }) => ( table.toggleAllPageRowsSelected(!!value)} aria-label="Select all" className="translate-y-[2px]" /> ), cell: ({ row }) => ( row.toggleSelected(!!value)} aria-label="Select row" className="translate-y-[2px]" /> ), enableSorting: false, enableHiding: false, }, { accessorKey: "name", header: ({ column }) => ( ), cell: ({ row }) => { return (
{row.getValue("name")}
) }, }, { accessorKey: "category", header: ({ column }) => ( ), cell: ({ row }) => { return (
{row.getValue("category") || "-"}
) }, }, { accessorKey: "description", header: ({ column }) => ( ), cell: ({ row }) => { return (
{row.getValue("description") || "-"}
) }, }, { accessorKey: "aplns", header: ({ column }) => ( ), cell: ({ row }) => { const aplns = row.getValue("aplns") as unknown as Array<{ seq: string; name?: string; emailAddress?: string; role: string; }>; const approvalLineText = formatApprovalLine(aplns); return (
{approvalLineText} {aplns?.length || 0}명
) }, }, { accessorKey: "createdAt", header: ({ column }) => ( ), cell: ({ row }) => { return (
{formatDate(row.getValue("createdAt"))}
) }, }, { accessorKey: "updatedAt", header: ({ column }) => ( ), cell: ({ row }) => { return (
{formatDate(row.getValue("updatedAt"))}
) }, }, { id: "actions", cell: ({ row }) => { 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, }, ] }