import { Badge, Divider, Group, Modal, SimpleGrid, Stack, Text } from '@mantine/core'; import type { WarehouseInventoryItem } from '@/types/warehouse'; import { InventoryStatusBadge } from './badges'; import { formatDate, formatNumber } from './options'; interface InventoryDetailModalProps { opened: boolean; onClose: () => void; item: WarehouseInventoryItem | null; } function DetailRow({ label, value }: { label: string; value: React.ReactNode }) { return ( {label} {value || '-'} ); } const noteLineValue = (notes: string | null | undefined, label: string) => { const match = notes?.match(new RegExp(`^${label}:\\s*(.+)$`, 'im')); return match?.[1]?.trim() ?? ''; }; export function InventoryDetailModal({ opened, onClose, item }: InventoryDetailModalProps) { const bookingReference = item?.booking?.reference ?? '-'; const handoverReference = item?.handoverDocumentReference ?? noteLineValue(item?.notes, 'Handover Reference'); const handoverDate = item?.handoverDocumentDate ?? noteLineValue(item?.notes, 'Generated At'); const inventorySummary = [ item?.status?.replace(/_/g, ' '), item?.grnNumber ? `GRN ${item.grnNumber}` : null, item?.releaseOrderReference ? `Release ${item.releaseOrderReference}` : null, handoverReference ? `Handover ${handoverReference}` : null, item?.warehouse ? `${item.warehouse.name} (${item.warehouse.code})` : null, ] .filter(Boolean) .join(' / '); return ( {!item ? ( No inventory item selected. ) : ( {bookingReference} {inventorySummary || 'Inventory information'} {item.inspectionStatus ?? 'Not inspected'}} /> {item.notes && ( <> {item.notes} )} )} ); }