'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'; export interface ClientRow { id: string; fullName: string; nationality: string | null; source: string | null; archivedAt: string | null; createdAt: string; yachtCount?: number; companyCount?: number; contacts?: Array<{ channel: string; value: string; isPrimary: boolean }>; tags?: Array<{ id: string; name: string; color: string }>; } const SOURCE_LABELS: Record = { website: 'Website', manual: 'Manual', referral: 'Referral', broker: 'Broker', }; interface GetColumnsOptions { portSlug: string; onEdit: (client: ClientRow) => void; onArchive: (client: ClientRow) => void; } export function getClientColumns({ portSlug, onEdit, onArchive, }: GetColumnsOptions): ColumnDef[] { return [ { id: 'fullName', accessorKey: 'fullName', header: 'Name', cell: ({ row }) => ( e.stopPropagation()} > {row.original.fullName} ), }, { id: 'primaryContact', header: 'Primary Contact', enableSorting: false, cell: ({ row }) => { const primary = row.original.contacts?.find((c) => c.isPrimary); if (!primary) return ; return ( {primary.channel}: {primary.value} ); }, }, { id: 'nationality', accessorKey: 'nationality', header: 'Nationality', cell: ({ getValue }) => ( {(getValue() as string | null) ?? '—'} ), }, { id: 'source', accessorKey: 'source', header: 'Source', cell: ({ getValue }) => { const source = getValue() as string | null; if (!source) return ; return ( {SOURCE_LABELS[source] ?? source} ); }, }, { id: 'yachtCount', header: 'Yachts', enableSorting: false, cell: ({ row }) => { const c = row.original.yachtCount ?? 0; return c === 0 ? ( ) : ( {c} ); }, }, { id: 'companyCount', header: 'Companies', enableSorting: false, cell: ({ row }) => { const c = row.original.companyCount ?? 0; return c === 0 ? ( ) : ( {c} ); }, }, { id: 'tags', header: 'Tags', enableSorting: false, cell: ({ row }) => { const clientTags = row.original.tags ?? []; if (clientTags.length === 0) return ; return (
{clientTags.slice(0, 3).map((tag) => ( ))} {clientTags.length > 3 && ( +{clientTags.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 ), }, ]; }