'use client'; import { type ColumnDef } from '@tanstack/react-table'; import { MoreHorizontal, Pencil, Activity } from 'lucide-react'; import { useRouter, useParams } from 'next/navigation'; import { Button } from '@/components/ui/button'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { TagBadge } from '@/components/shared/tag-badge'; export type BerthRow = { id: string; mooringNumber: string; area: string | null; status: string; lengthM: string | null; widthM: string | null; price: string | null; priceCurrency: string; tenureType: string; tags: Array<{ id: string; name: string; color: string }>; }; function StatusBadge({ status }: { status: string }) { const variants: Record = { available: 'bg-green-100 text-green-800 border-green-200', under_offer: 'bg-yellow-100 text-yellow-800 border-yellow-200', sold: 'bg-red-100 text-red-800 border-red-200', }; const labels: Record = { available: 'Available', under_offer: 'Under Offer', sold: 'Sold', }; return ( {labels[status] ?? status} ); } function ActionsCell({ row }: { row: { original: BerthRow } }) { const router = useRouter(); const params = useParams<{ portSlug: string }>(); const berth = row.original; return ( { e.stopPropagation(); router.push(`/${params.portSlug}/berths/${berth.id}`); }} > View details { e.stopPropagation(); router.push(`/${params.portSlug}/berths/${berth.id}?edit=true`); }} > Edit ); } export const berthColumns: ColumnDef[] = [ { accessorKey: 'mooringNumber', header: 'Mooring #', cell: ({ row }) => {row.original.mooringNumber}, }, { accessorKey: 'area', header: 'Area', cell: ({ row }) => row.original.area ?? '-', }, { accessorKey: 'status', header: 'Status', cell: ({ row }) => , }, { id: 'dimensions', header: 'Dimensions', enableSorting: false, cell: ({ row }) => { const { lengthM, widthM } = row.original; if (!lengthM && !widthM) return '-'; return `${lengthM ?? '?'}m × ${widthM ?? '?'}m`; }, }, { accessorKey: 'price', header: 'Price', cell: ({ row }) => { const { price, priceCurrency } = row.original; if (!price) return '-'; return new Intl.NumberFormat('en-US', { style: 'currency', currency: priceCurrency || 'USD', maximumFractionDigits: 0, }).format(Number(price)); }, }, { accessorKey: 'tenureType', header: 'Tenure', cell: ({ row }) => (row.original.tenureType === 'permanent' ? 'Permanent' : 'Fixed Term'), }, { id: 'tags', header: 'Tags', enableSorting: false, cell: ({ row }) => { const { tags } = row.original; if (!tags || tags.length === 0) return null; return (
{tags.slice(0, 3).map((tag) => ( ))} {tags.length > 3 && ( +{tags.length - 3} )}
); }, }, { id: 'actions', header: '', enableSorting: false, size: 48, cell: ({ row }) => , }, ];