'use client'; import Link from 'next/link'; import { type ColumnDef } from '@tanstack/react-table'; import { MoreHorizontal, Archive, Pencil } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { Badge } from '@/components/ui/badge'; import { RESIDENTIAL_STAGE_LABELS } from './residential-interest-filters'; export interface ResidentialInterestRow { id: string; residentialClientId: string; pipelineStage: string; source: string | null; notes: string | null; preferences: string | null; assignedTo: string | null; archivedAt: string | null; updatedAt: string; /** Optional client snapshot — server may join the residential client row * so the table can show the client name in column 1 without a second * fetch per row. */ clientName?: string | null; } export const RESIDENTIAL_INTEREST_COLUMN_OPTIONS: Array<{ id: string; label: string }> = [ { id: 'clientName', label: 'Client' }, { id: 'pipelineStage', label: 'Stage' }, { id: 'source', label: 'Source' }, { id: 'preferences', label: 'Preferences' }, { id: 'notes', label: 'Notes' }, { id: 'updatedAt', label: 'Updated' }, ]; export const RESIDENTIAL_INTEREST_DEFAULT_HIDDEN: string[] = []; interface GetColumnsOptions { portSlug: string; onEdit?: (interest: ResidentialInterestRow) => void; onArchive?: (interest: ResidentialInterestRow) => void; } export function getResidentialInterestColumns({ portSlug, onEdit, onArchive, }: GetColumnsOptions): ColumnDef[] { return [ { id: 'clientName', header: 'Client', cell: ({ row }) => { const r = row.original; const name = r.clientName ?? '—'; return ( e.stopPropagation()} > {name} ); }, }, { id: 'pipelineStage', accessorKey: 'pipelineStage', header: 'Stage', cell: ({ row }) => { const s = row.original.pipelineStage; return ( {RESIDENTIAL_STAGE_LABELS[s] ?? s} ); }, }, { id: 'source', accessorKey: 'source', header: 'Source', cell: ({ row }) => ( {row.original.source ?? '—'} ), }, { id: 'preferences', accessorKey: 'preferences', header: 'Preferences', enableSorting: false, cell: ({ row }) => ( {row.original.preferences ?? '—'} ), }, { id: 'notes', accessorKey: 'notes', header: 'Notes', enableSorting: false, cell: ({ row }) => ( {row.original.notes ?? '—'} ), }, { id: 'updatedAt', accessorKey: 'updatedAt', header: 'Updated', cell: ({ row }) => ( {new Date(row.original.updatedAt).toLocaleDateString()} ), }, { id: 'actions', header: '', enableSorting: false, size: 48, cell: ({ row }) => ( {onEdit ? ( onEdit(row.original)}> Edit ) : null} {onArchive ? ( onArchive(row.original)} className="text-destructive focus:text-destructive" > Archive ) : null} ), }, ]; }