import { useMemo } from 'react'; import { ActionIcon, Badge, Button, Group, Text, Tooltip } from '@mantine/core'; import { ArrowRightLeft, ClipboardList, Coins, History } from 'lucide-react'; import { DataTable, type ColumnDef } from '@edr/ui-common'; import type { InventoryAction, WarehouseInventoryItem } from '@/types/warehouse'; import { INVENTORY_NEXT_ACTION } from '@/types/warehouse'; import { InventoryStatusBadge } from './badges'; import { formatDate, formatNumber, humanizeEnum } from './options'; interface WarehouseInventoryTableProps { items: WarehouseInventoryItem[]; busyId?: string | null; onAdvance: (item: WarehouseInventoryItem, action: InventoryAction) => void; onMove: (item: WarehouseInventoryItem) => void; onHistory: (item: WarehouseInventoryItem) => void; onInspect?: (item: WarehouseInventoryItem) => void; onFeePreview?: (item: WarehouseInventoryItem) => void; } const itemKind = (item: WarehouseInventoryItem) => { if (item.containerId) return { label: 'Container', color: 'blue' }; if (item.cargoId) return { label: 'Cargo', color: 'grape' }; if (item.goodsId) return { label: 'Goods', color: 'orange' }; return { label: '—', color: 'gray' }; }; const actionColor: Record = { store: 'blue', reserve: 'grape', 'ready-for-loading': 'cyan', load: 'teal', dispatch: 'green', }; export function WarehouseInventoryTable({ items, busyId, onAdvance, onMove, onHistory, onInspect, onFeePreview, }: WarehouseInventoryTableProps) { const columns = useMemo[]>( () => [ { id: 'booking', header: 'Booking', cell: ({ row }) => row.original.bookingId ? ( {row.original.bookingId.slice(0, 8)}… ) : ( ), }, { id: 'facility', header: 'Facility', cell: ({ row }) => row.original.warehouse?.facility?.name ?? '—', }, { id: 'warehouse', header: 'Warehouse', cell: ({ row }) => row.original.warehouse?.code ?? '—' }, { id: 'yard', header: 'Yard', cell: ({ row }) => row.original.yard?.code ?? '—' }, { id: 'zone', header: 'Zone', cell: ({ row }) => row.original.zone?.code ?? '—' }, { id: 'item', header: 'Item', cell: ({ row }) => { const kind = itemKind(row.original); return ( {kind.label} ); }, }, { id: 'qty', header: 'Qty', cell: ({ row }) => formatNumber(row.original.quantity) }, { id: 'weight', header: 'Weight', cell: ({ row }) => formatNumber(row.original.weight) }, { id: 'status', header: 'Status', cell: ({ row }) => , }, { id: 'arrived', header: 'Arrived', cell: ({ row }) => {formatDate(row.original.arrivedAt)}, }, { id: 'actions', header: '', cell: ({ row }) => { const item = row.original; const busy = busyId === item.id; const nextAction = INVENTORY_NEXT_ACTION[item.status]; return ( e.stopPropagation()}> {nextAction && ( )} {item.status !== 'DISPATCHED' && ( onMove(item)}> )} {onInspect && ( onInspect(item)}> )} {onFeePreview && ( onFeePreview(item)}> )} onHistory(item)}> ); }, }, ], [busyId, onAdvance, onMove, onHistory, onInspect, onFeePreview], ); return ( ); }