"use client" import type { ColumnDef, Row } from "@tanstack/react-table" import type { ComponentType } from "react" import { MoreHorizontal, Pencil, Trash2 } from "lucide-react" import { Button } from "@/shared/components/ui/button" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/shared/components/ui/dropdown-menu" export type ActionsColumnExtraItem = { label: string icon?: ComponentType<{ className?: string }> onClick: (row: TData) => void | Promise variant?: "default" | "destructive" /** Hide the item entirely when false. Useful for permission gates. */ hidden?: boolean } export type ActionsColumnOptions = { onEdit?: (row: TData) => void onDelete?: (row: TData) => Promise /** Extra menu items rendered between Edit and Delete. */ extraItems?: (row: TData) => ActionsColumnExtraItem[] } export function createActionsColumn( options: ActionsColumnOptions, ): ColumnDef { return { id: "actions", header: () => Actions, cell: ({ row }) => , enableSorting: false, enableHiding: false, } } function ActionsCell({ row, options, }: { row: Row options: ActionsColumnOptions }) { return ( {options.onEdit && ( { e.stopPropagation() options.onEdit!(row.original) }}> Edit )} {options.extraItems?.(row.original) .filter((item) => !item.hidden) .map((item) => { const Icon = item.icon return ( { e.stopPropagation() void item.onClick(row.original) }} > {Icon ? : null} {item.label} ) })} {options.onDelete && ( { e.stopPropagation() options.onDelete!(row.original) }} > Delete )} ) }