"use client"; import Link from "next/link"; import type { Column, ColumnDef } from "@tanstack/react-table"; import { Icons } from "@/components/icons"; import { Badge } from "@/components/ui/badge"; import { DataTableColumnHeader } from "@/components/ui/table/data-table-column-header"; import { formatDate } from "@/lib/date-format"; import { formatNumber } from "@/lib/number-format"; import type { LeadReferenceData, LeadSummary } from "../api/types"; import { LeadCellAction } from "./lead-cell-action"; export function getLeadColumns({ referenceData, canUpdate, canDelete, canAssign, }: { referenceData: LeadReferenceData; canUpdate: boolean; canDelete: boolean; canAssign: boolean; }): ColumnDef[] { return [ { id: "code", accessorKey: "code", header: ({ column }: { column: Column }) => ( ), cell: ({ row }) => (
{row.original.code} {row.original.customerName ?? "-"}
), meta: { label: "Lead Code", placeholder: "Search leads...", variant: "text" as const, icon: Icons.search, }, enableColumnFilter: true, }, { id: "status", accessorFn: (row) => row.status, header: ({ column }: { column: Column }) => ( ), cell: ({ row }) => ( {row.original.statusLabel ?? row.original.status} ), meta: { label: "Document Status", variant: "select" as const, options: referenceData.statuses.map((item) => ({ label: item.label, value: item.id, })), }, enableColumnFilter: true, }, { id: "process_status", accessorFn: (row) => row.status, header: ({ column }: { column: Column }) => ( ), cell: ({ row }) => ( {row.original.statusLabel ?? row.original.status} ), meta: { label: "Process Status", variant: "select" as const, options: referenceData.statuses.map((item) => ({ label: item.label, value: item.id, })), }, enableColumnFilter: true, }, { id: "branchId", accessorFn: (row) => row.branchId ?? "", header: ({ column }: { column: Column }) => ( ), cell: ({ row }) => { const branch = referenceData.branches.find( (item) => item.id === row.original.branchId, ); return {branch?.name ?? "-"}; }, meta: { label: "Branch", variant: "select" as const, options: referenceData.branches.map((item) => ({ label: item.name, value: item.id, })), }, enableColumnFilter: true, }, { id: "customerId", accessorFn: (row) => row.customerId ?? "", header: ({ column }: { column: Column }) => ( ), cell: ({ row }) => {row.original.customerName ?? "-"}, meta: { label: "Customer", variant: "select" as const, options: referenceData.customers.map((item) => ({ label: `${item.name} (${item.code})`, value: item.id, })), }, enableColumnFilter: true, }, { id: "projectName", accessorKey: "projectName", header: ({ column }: { column: Column }) => ( ), cell: ({ row }) => {row.original.projectName ?? "-"}, }, { id: "priority", accessorFn: (row) => row.priority ?? "", header: ({ column }: { column: Column }) => ( ), cell: ({ row }) => {row.original.priority ?? "-"}, }, { id: "suggestedSalesOwner", accessorFn: (row) => row.suggestedSalesOwnerId ?? "", header: ({ column }: { column: Column }) => ( ), cell: ({ row }) => ( {row.original.suggestedSalesOwnerName ?? "-"} ), }, { id: "assignedSalesOwner", accessorFn: (row) => row.assignedSalesOwnerId ?? "", header: ({ column }: { column: Column }) => ( ), cell: ({ row }) => ( {row.original.assignedSalesOwnerName ?? "-"} ), }, { id: "estimatedValue", accessorKey: "estimatedValue", header: ({ column }: { column: Column }) => ( ), cell: ({ row }) => ( {row.original.estimatedValue !== null ? formatNumber(row.original.estimatedValue) : "-"} ), }, { id: "createdAt", accessorKey: "createdAt", header: ({ column }: { column: Column }) => ( ), cell: ({ row }) => {formatDate(row.original.createdAt)}, }, { id: "actions", cell: ({ row }) => ( ), }, ]; }