'use client'; import Link from 'next/link'; import { format } from 'date-fns'; import { MoreHorizontal, Pencil, Archive } from 'lucide-react'; import type { ColumnDef } from '@tanstack/react-table'; import { Button } from '@/components/ui/button'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { Badge } from '@/components/ui/badge'; import { TagBadge } from '@/components/shared/tag-badge'; import { stageBadgeClass, stageLabel } from '@/lib/constants'; export interface InterestRow { id: string; clientId: string; clientName: string | null; berthId: string | null; berthMooringNumber: string | null; pipelineStage: string; leadCategory: string | null; source: string | null; archivedAt: string | null; createdAt: string; tags?: Array<{ id: string; name: string; color: string }>; } const CATEGORY_LABELS: Record = { general_interest: 'General Interest', specific_qualified: 'Specific Qualified', hot_lead: 'Hot Lead', }; const SOURCE_LABELS: Record = { website: 'Website', manual: 'Manual', referral: 'Referral', broker: 'Broker', }; interface GetColumnsOptions { portSlug: string; onEdit: (interest: InterestRow) => void; onArchive: (interest: InterestRow) => void; } export function getInterestColumns({ portSlug, onEdit, onArchive, }: GetColumnsOptions): ColumnDef[] { return [ { id: 'clientName', accessorKey: 'clientName', header: 'Client', cell: ({ row }) => ( e.stopPropagation()} > {row.original.clientName ?? '—'} ), }, { id: 'berthMooringNumber', accessorKey: 'berthMooringNumber', header: 'Berth', cell: ({ row }) => { if (!row.original.berthId || !row.original.berthMooringNumber) { return ; } return ( e.stopPropagation()} > {row.original.berthMooringNumber} ); }, }, { id: 'pipelineStage', accessorKey: 'pipelineStage', header: 'Stage', cell: ({ getValue }) => { const stage = getValue() as string; return ( {stageLabel(stage)} ); }, }, { id: 'leadCategory', accessorKey: 'leadCategory', header: 'Category', cell: ({ getValue }) => { const cat = getValue() as string | null; if (!cat) return ; return ( {CATEGORY_LABELS[cat] ?? cat} ); }, }, { id: 'source', accessorKey: 'source', header: 'Source', cell: ({ getValue }) => { const source = getValue() as string | null; if (!source) return ; return ( {SOURCE_LABELS[source] ?? source} ); }, }, { id: 'tags', header: 'Tags', enableSorting: false, cell: ({ row }) => { const rowTags = row.original.tags ?? []; if (rowTags.length === 0) return ; return (
{rowTags.slice(0, 3).map((tag) => ( ))} {rowTags.length > 3 && ( +{rowTags.length - 3} )}
); }, }, { id: 'createdAt', accessorKey: 'createdAt', header: 'Created', cell: ({ getValue }) => ( {format(new Date(getValue() as string), 'MMM d, yyyy')} ), }, { id: 'actions', header: '', enableSorting: false, size: 48, cell: ({ row }) => ( onEdit(row.original)}> Edit onArchive(row.original)}> Archive ), }, ]; }