"use client"; import { type ColumnDef } from "@tanstack/react-table"; import { MoreHorizontal, Pencil, Archive, Trash2, FlaskConical } from "lucide-react"; import { DataTableColumnHeader } from "@/components/shared/data-table-column-header"; import { StatusBadge, getStockStatus } from "@/components/shared/status-badge"; import { ColorSwatch } from "@/components/shared/color-swatch"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; export interface ResinRow { id: string; name: string; brand: string; resinType: string; color: string; colorHex: string; bottleSize: number; usedML: number; cost: number | null; purchaseDate: Date | null; notes: string | null; archived: boolean; vendor: { id: string; name: string } | null; location: { id: string; name: string } | null; } interface ResinColumnsProps { onEdit: (resin: ResinRow) => void; onArchive: (id: string) => void; onDelete: (id: string) => void; onLogUsage: (resin: ResinRow) => void; lowStockThreshold: number; } export function getResinColumns({ onEdit, onArchive, onDelete, onLogUsage, lowStockThreshold, }: ResinColumnsProps): ColumnDef[] { return [ { id: "color", header: "", cell: ({ row }) => , enableHiding: false, size: 40, }, { accessorKey: "name", header: ({ column }) => , cell: ({ row }) => { const remaining = row.original.bottleSize - row.original.usedML; const status = getStockStatus( remaining, row.original.bottleSize, lowStockThreshold, row.original.archived ); return (
{row.original.name}
); }, enableHiding: false, }, { accessorKey: "brand", header: ({ column }) => , cell: ({ row }) => ( {row.original.brand} ), }, { accessorKey: "resinType", header: ({ column }) => , cell: ({ row }) => ( {row.original.resinType} ), }, { id: "remaining", header: ({ column }) => , cell: ({ row }) => { const remaining = row.original.bottleSize - row.original.usedML; const percent = row.original.bottleSize > 0 ? (remaining / row.original.bottleSize) * 100 : 0; const isLow = percent <= lowStockThreshold; return (
{remaining.toFixed(0)} ml
); }, }, { id: "location", header: "Location", cell: ({ row }) => ( {row.original.location?.name ?? "\u2014"} ), }, { id: "vendor", header: "Vendor", cell: ({ row }) => ( {row.original.vendor?.name ?? "\u2014"} ), }, { accessorKey: "cost", header: ({ column }) => , cell: ({ row }) => ( {row.original.cost != null ? `\u20AC${row.original.cost.toFixed(2)}` : "\u2014"} ), }, { id: "actions", cell: ({ row }) => ( onEdit(row.original)}> Edit onLogUsage(row.original)}> Log Usage onArchive(row.original.id)}> {row.original.archived ? "Unarchive" : "Archive"} onDelete(row.original.id)} className="text-destructive focus:text-destructive" > Delete ), enableHiding: false, }, ]; }