import { Badge, Card, Group, Loader, Modal, Stack, Text } from '@mantine/core'; import { CalendarClock, Coins } from 'lucide-react'; import { useFeePreview } from '@/hooks/useWarehouses'; import type { FeePreview } from '@/types/warehouse'; interface FeePreviewModalProps { opened: boolean; onClose: () => void; inventoryId: string | null; } const LABELS: Record = { DEMURRAGE_FEE: { label: 'Demurrage', color: 'orange' }, STORAGE_FEE: { label: 'Storage', color: 'teal' }, }; function fmtDate(iso: string | null) { if (!iso) return '—'; return new Date(iso).toLocaleDateString(); } function FeeCard({ fee }: { fee: FeePreview }) { const meta = LABELS[fee.ruleType] ?? { label: fee.ruleType, color: 'gray' }; const configured = Boolean(fee.ruleId); return ( {meta.label} {fee.endIsOpen && ( accruing )} {fee.amount.toLocaleString()} {fee.currency} {!configured ? ( No active {meta.label.toLowerCase()} rule configured — amount shown as 0. ) : ( )} ); } function Row({ label, value }: { label: string; value: string }) { return ( {label} {value} ); } /** Batch 5 — automatic storage/demurrage fee preview for an inventory item (no invoice/payment). */ export function FeePreviewModal({ opened, onClose, inventoryId }: FeePreviewModalProps) { const { data, isLoading } = useFeePreview(opened ? inventoryId ?? undefined : undefined); return ( Storage & Demurrage Preview } centered size="md" > {isLoading ? ( ) : ( {(data ?? []).map((fee) => ( ))} Preview only — invoicing & payment are handled in Batch 6. Charges accrue from arrival until gate clearance / release (or today if still in terminal). )} ); }