import { useEffect, useMemo, useState } from 'react'; import { Alert, Badge, Button, Checkbox, Group, Loader, Modal, NumberInput, Select, Stack, Table, Tabs, Text, Textarea, TextInput, } from '@mantine/core'; import { Info, PackageSearch, Truck } from 'lucide-react'; import { useToast } from '@/hooks/use-toast'; import { useBulkReceive, useEligibleBookings, useLoadPassedExport, useReceiveInventory, useWarehouseYards, useWarehouseZones, useWarehouses, } from '@/hooks/useWarehouses'; import type { BulkReceiveResult, LoadPassedExportResult, ReceiveInventoryPayload } from '@/types/warehouse'; import { BookingSelect } from './BookingSelect'; import { extractErrorMessage, formatNumber } from './options'; interface ReceiveInventoryModalProps { opened: boolean; onClose: () => void; /** When supplied the modal locks to a single booking (legacy single-receive). */ bookingId?: string; bookingLabel?: string; onReceived?: () => void; } interface Location { warehouseId: string; yardId: string; zoneId: string; } /** Cascading Warehouse → Yard → Zone selectors (ACTIVE only). */ function LocationSelects({ value, onChange, }: { value: Location; onChange: (next: Location) => void; }) { const warehousesQuery = useWarehouses({ status: 'ACTIVE' }); const yardsQuery = useWarehouseYards(value.warehouseId || undefined); const zonesQuery = useWarehouseZones(value.yardId || undefined); const warehouseOptions = useMemo( () => (warehousesQuery.data ?? []).map((w) => ({ value: w.id, label: `${w.name} (${w.code})` })), [warehousesQuery.data], ); const yardOptions = useMemo( () => (yardsQuery.data ?? []) .filter((y) => y.status === 'ACTIVE') .map((y) => ({ value: y.id, label: `${y.name} (${y.code})` })), [yardsQuery.data], ); const zoneOptions = useMemo( () => (zonesQuery.data ?? []) .filter((z) => z.status === 'ACTIVE') .map((z) => ({ value: z.id, label: `${z.name} (${z.code})` })), [zonesQuery.data], ); return ( onChange({ ...value, yardId: v ?? '', zoneId: '' })} />