import { ActionIcon, Badge, Button, Group, Table, Text, Tooltip } from '@mantine/core'; import { ArrowRightLeft, ClipboardList, Coins, History } from 'lucide-react'; 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) { if (items.length === 0) { return ( No inventory items found. ); } return ( Booking Facility Warehouse Yard Zone Item Qty Weight Status Arrived Actions {items.map((item) => { const kind = itemKind(item); const busy = busyId === item.id; const nextAction = INVENTORY_NEXT_ACTION[item.status]; return ( {item.bookingId ? ( {item.bookingId.slice(0, 8)}… ) : ( )} {item.warehouse?.facility?.name ?? '—'} {item.warehouse?.code ?? '—'} {item.yard?.code ?? '—'} {item.zone?.code ?? '—'} {kind.label} {formatNumber(item.quantity)} {formatNumber(item.weight)} {formatDate(item.arrivedAt)} {nextAction && ( )} {item.status !== 'DISPATCHED' && ( onMove(item)}> )} {onInspect && ( onInspect(item)}> )} {onFeePreview && ( onFeePreview(item)}> )} onHistory(item)}> ); })}
); }