import React, { useState, useEffect } from 'react'; import { useSearchParams } from 'react-router-dom'; import { Plus, Search, Package, AlertTriangle, Database, Truck, Activity, Archive, BarChart3, Clock, X, Edit2, PlusCircle, Eye, ChevronLeft, ChevronRight, ChevronsLeft, ChevronsRight } from 'lucide-react'; import { motion } from 'framer-motion'; import { Card } from '../../components/Common'; import { fleetApi } from '../../api/fleet'; interface InventoryItem { id: string; name: string; category: string; totalStock: number; minStock: number; maxStock: number; unit: string; expiringSoon: number; supplierDetails: string; leadTimeDays: number; vehicles: { vehicleId: string; stock: number }[]; } interface InventoryMetadata { categories: string[]; units: string[]; commonNames: Record; } export const FleetInventory: React.FC = () => { const [inventory, setInventory] = useState([]); const [selectedItem, setSelectedItem] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [searchQuery, setSearchQuery] = useState(''); const [isSearchFocused, setIsSearchFocused] = useState(false); const [page, setPage] = useState(1); const [itemsPerPage, setItemsPerPage] = useState(5); const [pendingRequests, setPendingRequests] = useState([]); const [loadingRequests, setLoadingRequests] = useState(true); const [, setSearchParams] = useSearchParams(); // Metadata states const [metadata, setMetadata] = useState({ categories: [], units: [], commonNames: {} }); // Modal / Form states const [showAddModal, setShowAddModal] = useState(false); const [showDetailsModal, setShowDetailsModal] = useState(false); const [formCategory, setFormCategory] = useState('MEDICATION'); const [formNameType, setFormNameType] = useState<'standard' | 'custom'>('standard'); const [formNameStandard, setFormNameStandard] = useState(''); const [formNameCustom, setFormNameCustom] = useState(''); const [formUnit, setFormUnit] = useState('Tablet'); const [formMinStock, setFormMinStock] = useState(30); const [formMaxStock, setFormMaxStock] = useState(150); const [formSupplier, setFormSupplier] = useState(''); const [formLeadTime, setFormLeadTime] = useState(3); const [isSubmitting, setIsSubmitting] = useState(false); const [submitError, setSubmitError] = useState(null); // Single Restock states const [showSingleRestockModal, setShowSingleRestockModal] = useState(false); const [singleRestockQuantity, setSingleRestockQuantity] = useState(100); const [singleRestockReason, setSingleRestockReason] = useState('Shipment from HealthCare Distributors'); const [singleRestockIsSubmitting, setSingleRestockIsSubmitting] = useState(false); const [singleRestockError, setSingleRestockError] = useState(null); // Bulk Restock states interface BulkRestockRow { itemId: string; quantity: number; reason: string; } const [showBulkRestockModal, setShowBulkRestockModal] = useState(false); const [bulkRestockRows, setBulkRestockRows] = useState([ { itemId: '', quantity: 100, reason: 'Shipment from HealthCare Distributors' } ]); const [bulkRestockIsSubmitting, setBulkRestockIsSubmitting] = useState(false); const [bulkRestockError, setBulkRestockError] = useState(null); // Assign to Vehicle states interface AssignVehicleRow { itemId: string; quantity: number; batch_number: string; expiry_date: string; } const [showAssignVehicleModal, setShowAssignVehicleModal] = useState(false); const [assignVehicleId, setAssignVehicleId] = useState(''); const [assignSupplierName, setAssignSupplierName] = useState('Central Warehouse'); const [assignReason, setAssignReason] = useState('Ambulance Initial Stocking'); const [assignVehicleRows, setAssignVehicleRows] = useState([ { itemId: '', quantity: 100, batch_number: '', expiry_date: '' } ]); const [assignVehicleIsSubmitting, setAssignVehicleIsSubmitting] = useState(false); const [assignVehicleError, setAssignVehicleError] = useState(null); const [vehiclesList, setVehiclesList] = useState([]); useEffect(() => { const fetchVehicles = async () => { try { const token = localStorage.getItem('teleems_token') || ''; const userStr = localStorage.getItem('teleems_user'); let orgId = ''; if (userStr) { const u = JSON.parse(userStr); orgId = u.organisationId || ''; } const res = await fleetApi.getVehicles(token, orgId); const data = res?.data?.data || res?.data || []; setVehiclesList(Array.isArray(data) ? data : []); } catch (e) { console.error('Failed to fetch vehicles:', e); } }; fetchVehicles(); }, []); const handleSubmitAssignVehicle = async (e: React.FormEvent) => { e.preventDefault(); setAssignVehicleError(null); setAssignVehicleIsSubmitting(true); if (!assignVehicleId) { setAssignVehicleError('Please select a vehicle.'); setAssignVehicleIsSubmitting(false); return; } if (assignVehicleRows.length === 0) { setAssignVehicleError('Please add at least one item to assign.'); setAssignVehicleIsSubmitting(false); return; } const invalidRow = assignVehicleRows.find(row => !row.itemId || row.quantity <= 0); if (invalidRow) { setAssignVehicleError('Please ensure all rows have an item selected and a positive quantity.'); setAssignVehicleIsSubmitting(false); return; } try { const token = localStorage.getItem('teleems_token') || ''; const payload = { supplier_name: assignSupplierName, reason: assignReason, items: assignVehicleRows.map(row => ({ itemId: row.itemId, quantity: Number(row.quantity), batch_number: row.batch_number || 'N/A', expiry_date: row.expiry_date || new Date(new Date().setFullYear(new Date().getFullYear() + 1)).toISOString().split('T')[0] })) }; await fleetApi.assignToVehicle(assignVehicleId, payload, token); alert(`Successfully assigned inventory to vehicle!`); setShowAssignVehicleModal(false); } catch (err: any) { console.error('Failed to assign to vehicle:', err); setAssignVehicleError(err?.message || 'Failed to submit assignment. Check item details or try again.'); } finally { setAssignVehicleIsSubmitting(false); } }; const handleSubmitSingleRestock = async (e: React.FormEvent) => { e.preventDefault(); if (!selectedItem) return; setSingleRestockError(null); setSingleRestockIsSubmitting(true); if (singleRestockQuantity <= 0) { setSingleRestockError('Please specify a positive quantity to restock.'); setSingleRestockIsSubmitting(false); return; } try { const token = localStorage.getItem('teleems_token') || ''; const payload = [ { itemId: selectedItem.id, quantity: Number(singleRestockQuantity), reason: singleRestockReason || 'Routine stock replenishment' } ]; await fleetApi.restockInventory(payload, token); // Update stock level locally setInventory(prev => prev.map(item => { if (item.id === selectedItem.id) { return { ...item, totalStock: item.totalStock + Number(singleRestockQuantity) }; } return item; })); setSelectedItem(prev => { if (prev && prev.id === selectedItem.id) { return { ...prev, totalStock: prev.totalStock + Number(singleRestockQuantity) }; } return prev; }); // Show success notification and close modal alert(`Successfully restocked ${singleRestockQuantity} units of ${selectedItem.name}!`); setShowSingleRestockModal(false); } catch (err: any) { console.error('Failed to restock item:', err); setSingleRestockError(err?.message || 'Failed to submit restock request. Please verify the connection.'); } finally { setSingleRestockIsSubmitting(false); } }; const handleSubmitBulkRestock = async (e: React.FormEvent) => { e.preventDefault(); setBulkRestockError(null); setBulkRestockIsSubmitting(true); // Validate rows if (bulkRestockRows.length === 0) { setBulkRestockError('Please add at least one item to restock.'); setBulkRestockIsSubmitting(false); return; } const invalidRow = bulkRestockRows.find(row => !row.itemId || row.quantity <= 0); if (invalidRow) { setBulkRestockError('Please ensure all rows have an item selected and a positive quantity.'); setBulkRestockIsSubmitting(false); return; } try { const token = localStorage.getItem('teleems_token') || ''; const payload = bulkRestockRows.map(row => ({ itemId: row.itemId, quantity: Number(row.quantity), reason: row.reason || 'Bulk Shipment' })); await fleetApi.restockInventory(payload, token); // Update local stock levels for all successfully restocked items setInventory(prev => prev.map(item => { const restockMatch = bulkRestockRows.find(row => row.itemId === item.id); if (restockMatch) { return { ...item, totalStock: item.totalStock + Number(restockMatch.quantity) }; } return item; })); // Update selected item details locally too if it was restocked setSelectedItem(prev => { if (prev) { const restockMatch = bulkRestockRows.find(row => row.itemId === prev.id); if (restockMatch) { return { ...prev, totalStock: prev.totalStock + Number(restockMatch.quantity) }; } } return prev; }); alert(`Successfully processed bulk restock for ${bulkRestockRows.length} items!`); setShowBulkRestockModal(false); } catch (err: any) { console.error('Failed bulk restock:', err); setBulkRestockError(err?.message || 'Failed to submit bulk restock. Check item compatibility or try again.'); } finally { setBulkRestockIsSubmitting(false); } }; // Dynamic selector values based on category const getSortedUnits = () => { return metadata.units; }; // Fetch category-specific metadata dynamically from backend when Category selection changes useEffect(() => { const fetchCategorySpecificMetadata = async () => { try { const token = localStorage.getItem('teleems_token') || ''; if (!token) return; const response = await fleetApi.getInventoryMetadata(token, formCategory); const metaData = response?.data?.data || response?.data; if (metaData) { let categoryNames: string[] = []; if (metaData.common_names) { if (Array.isArray(metaData.common_names)) { categoryNames = metaData.common_names; } else if (metaData.common_names[formCategory]) { categoryNames = metaData.common_names[formCategory]; } else if (typeof metaData.common_names === 'object') { const values = Object.values(metaData.common_names); const foundArray = values.find(val => Array.isArray(val)); if (foundArray) { categoryNames = foundArray as string[]; } } } if (categoryNames.length === 0) { categoryNames = []; } setMetadata(prev => ({ categories: prev.categories, units: metaData.units || prev.units, commonNames: { ...prev.commonNames, [formCategory]: categoryNames } })); } } catch (err) { console.warn(`Failed to fetch metadata for category ${formCategory}:`, err); } }; fetchCategorySpecificMetadata(); }, [formCategory]); // Synchronize dynamic selector value standard selection lists and category preferred unit formats useEffect(() => { // 1. Manage Dynamic Medicine Selection list const list = metadata.commonNames[formCategory] || []; if (list.length > 0) { setFormNameStandard(list[0]); setFormNameType('standard'); } else { setFormNameStandard(''); setFormNameType('custom'); } // 2. Manage Dynamic Category-Based Unit pre-selection if (metadata.units.length > 0) { setFormUnit(metadata.units[0]); } }, [formCategory, metadata.commonNames, metadata.units]); // Edit Modal / Form states const [showEditModal, setShowEditModal] = useState(false); const [editCategoryId, setEditCategoryId] = useState(''); const [formEditCategory, setFormEditCategory] = useState('MEDICATION'); const [formEditName, setFormEditName] = useState(''); const [formEditUnit, setFormEditUnit] = useState('Tablet'); const [formEditMinStock, setFormEditMinStock] = useState(30); const [formEditMaxStock, setFormEditMaxStock] = useState(150); const [formEditSupplier, setFormEditSupplier] = useState(''); const [formEditLeadTime, setFormEditLeadTime] = useState(3); const [isEditingSubmitting, setIsEditingSubmitting] = useState(false); const [editSubmitError, setEditSubmitError] = useState(null); const getSortedEditUnits = () => { return metadata.units; }; const handleOpenEditModal = (item: InventoryItem) => { setEditCategoryId(item.id); setFormEditCategory(item.category); setFormEditName(item.name); const formattedUnit = item.unit.charAt(0).toUpperCase() + item.unit.slice(1).toLowerCase(); setFormEditUnit(formattedUnit); setFormEditMinStock(item.minStock); setFormEditMaxStock(item.maxStock); setFormEditSupplier(item.supplierDetails); setFormEditLeadTime(item.leadTimeDays); setEditSubmitError(null); setShowEditModal(true); }; // Fetch category-specific metadata dynamically from backend when edit Category selection changes useEffect(() => { if (showEditModal) { const fetchCategorySpecificMetadata = async () => { try { const token = localStorage.getItem('teleems_token') || ''; if (!token) return; const response = await fleetApi.getInventoryMetadata(token, formEditCategory); const metaData = response?.data?.data || response?.data; if (metaData) { let categoryNames: string[] = []; if (metaData.common_names) { if (Array.isArray(metaData.common_names)) { categoryNames = metaData.common_names; } else if (metaData.common_names[formEditCategory]) { categoryNames = metaData.common_names[formEditCategory]; } else if (typeof metaData.common_names === 'object') { const values = Object.values(metaData.common_names); const foundArray = values.find(val => Array.isArray(val)); if (foundArray) { categoryNames = foundArray as string[]; } } } if (categoryNames.length === 0) { categoryNames = []; } setMetadata(prev => ({ categories: prev.categories, units: metaData.units || prev.units, commonNames: { ...prev.commonNames, [formEditCategory]: categoryNames } })); } } catch (err) { console.warn(`Failed to fetch metadata for category ${formEditCategory}:`, err); } }; fetchCategorySpecificMetadata(); } }, [formEditCategory, showEditModal]); const handleSubmitEditStock = async (e: React.FormEvent) => { e.preventDefault(); setEditSubmitError(null); setIsEditingSubmitting(true); if (!formEditName.trim()) { setEditSubmitError('Supply item name is required.'); setIsEditingSubmitting(false); return; } try { const token = localStorage.getItem('teleems_token') || ''; const payload = { name: formEditName, category: formEditCategory, unit: formEditUnit, min_stock_threshold: Number(formEditMinStock), max_stock_level: Number(formEditMaxStock), supplier_details: formEditSupplier || 'Generic Supplier Distributors', lead_time_days: Number(formEditLeadTime) }; await fleetApi.updateInventoryMaster(editCategoryId, payload, token); setInventory(prev => prev.map(item => { if (item.id === editCategoryId) { return { ...item, name: formEditName, category: formEditCategory, unit: formEditUnit.toUpperCase(), minStock: Number(formEditMinStock), maxStock: Number(formEditMaxStock), supplierDetails: formEditSupplier || 'Generic Supplier Distributors', leadTimeDays: Number(formEditLeadTime) }; } return item; })); setSelectedItem(prev => { if (prev && prev.id === editCategoryId) { return { ...prev, name: formEditName, category: formEditCategory, unit: formEditUnit.toUpperCase(), minStock: Number(formEditMinStock), maxStock: Number(formEditMaxStock), supplierDetails: formEditSupplier || 'Generic Supplier Distributors', leadTimeDays: Number(formEditLeadTime) }; } return prev; }); setShowEditModal(false); } catch (err: any) { console.error('Failed to update inventory master:', err); setEditSubmitError(err?.message || 'Failed to update supply item details.'); } finally { setIsEditingSubmitting(false); } }; useEffect(() => { const fetchInventoryAndMetadata = async () => { setLoading(true); setError(null); try { const token = localStorage.getItem('teleems_token') || ''; if (!token) { setError('Authentication token not found. Please log in again.'); return; } // Fetch master list and metadata in parallel const [response, metaResponse] = await Promise.all([ fleetApi.getInventoryMaster(token), fleetApi.getInventoryMetadata(token).catch(e => { console.warn('Metadata fetch failed, using fallbacks:', e); return null; }) ]); // Process metadata response if (metaResponse) { const metaData = metaResponse?.data?.data || metaResponse?.data; if (metaData) { setMetadata({ categories: metaData.categories || [], units: metaData.units || [], commonNames: metaData.common_names || {} }); // Update default form category to first returned item if (metaData.categories && metaData.categories.length > 0) { setFormCategory(metaData.categories[0]); } if (metaData.units && metaData.units.length > 0) { setFormUnit(metaData.units[0]); } } } // Handle the various structures returned by the backend let rawList = response?.data?.data || response?.data || (Array.isArray(response) ? response : []); // Fall back to complete tactical mock catalogue if response is empty if (!rawList || rawList.length === 0) { rawList = []; } // Map the API fields to our UI-friendly model with rich, simulated telemetry where needed const mappedList: InventoryItem[] = rawList.map((item: any, index: number) => { const minStock = item.min_stock_threshold || 20; const maxStock = item.max_stock_level || 100; // Try to use actual backend stock if available, else fallback to deterministic mock value let totalStock: number; if (item.totalStock !== undefined) { totalStock = Number(item.totalStock); } else if (item.current_stock !== undefined) { totalStock = Number(item.current_stock); } else if (item.total_stock !== undefined) { totalStock = Number(item.total_stock); } else if (item.stock !== undefined) { totalStock = Number(item.stock); } else if (item.quantity !== undefined) { totalStock = Number(item.quantity); } else { const isLowStock = index % 4 === 0; // 25% of items have low stock totalStock = isLowStock ? Math.floor(minStock * 0.6) : Math.floor(minStock + (maxStock - minStock) * 0.4); } // Expiring soon count const expiringSoon = index % 5 === 0 ? Math.floor(minStock * 0.15) : 0; // Distribute stock across mock vehicles const v1 = Math.floor(totalStock * 0.4); const v2 = Math.floor(totalStock * 0.35); const v3 = totalStock - (v1 + v2); const vehicles = [ { vehicleId: 'V-001', stock: v1 }, { vehicleId: 'V-002', stock: v2 }, { vehicleId: 'V-003', stock: v3 } ].filter(v => v.stock > 0); return { id: item.id || `ITM-00${index + 1}`, name: item.name || 'Unknown Supply Item', category: item.category || 'GENERAL', totalStock, minStock, maxStock, unit: item.unit_of_measure || 'UNITS', expiringSoon, supplierDetails: item.supplier_details || 'Generic Supplier Distributors', leadTimeDays: item.lead_time_days || 3, vehicles }; }); setInventory(mappedList); // Auto-select the first item on load if (mappedList.length > 0) { setSelectedItem(mappedList[0]); } } catch (err: any) { console.error('Failed to fetch inventory master:', err); setError(err?.message || 'Failed to sync with tactical stock catalog.'); } finally { setLoading(false); } }; fetchInventoryAndMetadata(); }, []); useEffect(() => { const fetchRequests = async () => { try { const token = localStorage.getItem('teleems_token') || ''; if (!token) return; const res = await fleetApi.getPendingRestockRequests(token); const data = res?.data?.data || res?.data || []; setPendingRequests(Array.isArray(data) ? data : []); } catch (err) { console.error('Failed to fetch pending requests:', err); } finally { setLoadingRequests(false); } }; fetchRequests(); }, []); const handleSubmitAddStock = async (e: React.FormEvent) => { e.preventDefault(); setSubmitError(null); setIsSubmitting(true); const nameToSubmit = formNameType === 'standard' ? formNameStandard : formNameCustom; if (!nameToSubmit.trim()) { setSubmitError('Supply item name is required.'); setIsSubmitting(false); return; } try { const token = localStorage.getItem('teleems_token') || ''; const payload = [ { name: nameToSubmit, category: formCategory, unit: formUnit, min_stock_threshold: Number(formMinStock), max_stock_level: Number(formMaxStock), supplier_details: formSupplier || 'Generic Supplier Distributors', lead_time_days: Number(formLeadTime) } ]; await fleetApi.createInventoryMaster(payload, token); // Build UI-friendly representation for local state update const newLocalItem: InventoryItem = { id: `ITM-${Math.floor(Math.random() * 900000 + 100000)}`, name: nameToSubmit, category: formCategory, totalStock: Math.floor(formMinStock + (formMaxStock - formMinStock) * 0.4), // healthy initial stock minStock: Number(formMinStock), maxStock: Number(formMaxStock), unit: formUnit.toUpperCase(), // consistent capitalization expiringSoon: 0, supplierDetails: formSupplier || 'Generic Supplier Distributors', leadTimeDays: Number(formLeadTime), vehicles: [] }; setInventory(prev => [newLocalItem, ...prev]); setSelectedItem(newLocalItem); // Reset modal state setShowAddModal(false); setFormNameCustom(''); setFormSupplier(''); } catch (err: any) { console.error('Failed to create inventory master:', err); setSubmitError(err?.message || 'Failed to register the new supply item.'); } finally { setIsSubmitting(false); } }; // Filter inventory based on search input const filteredInventory = inventory.filter(item => item.name?.toLowerCase().includes(searchQuery.toLowerCase()) || item.category?.toLowerCase().includes(searchQuery.toLowerCase()) || item.id?.toLowerCase().includes(searchQuery.toLowerCase()) ); const totalPages = Math.max(1, Math.ceil(filteredInventory.length / itemsPerPage)); const safePage = Math.min(page, totalPages); const pageData = filteredInventory.slice((safePage - 1) * itemsPerPage, safePage * itemsPerPage); // Dynamic calculations for stats const totalSKUs = inventory.length; const lowStockCount = inventory.filter(item => item.totalStock < item.minStock).length; const expiringSoonCount = inventory.reduce((sum, item) => sum + (item.expiringSoon || 0), 0); const consumptionMtd = `₹${(inventory.length * 4.2 || 42.5).toFixed(1)}k`; return (
{/* Top Stats */}
+12%
{loading ? '...' : totalSKUs}
TOTAL SKUs
{loading ? '...' : lowStockCount}
LOW STOCK ITEMS
{loading ? '...' : expiringSoonCount}
EXPIRING (30D)
{loadingRequests ? '...' : pendingRequests.length}
PENDING REQUESTS
{ setSearchQuery(e.target.value); setPage(1); }} onFocus={() => setIsSearchFocused(true)} onBlur={() => setIsSearchFocused(false)} className="stations-search-input" style={{ background: 'transparent', border: 'none', color: '#0F172A', fontSize: '0.875rem', width: '100%', outline: 'none', paddingRight: searchQuery ? '24px' : '0' }} /> {searchQuery && ( )}
{loading ? (
DECRYPTING STOCK CATALOG...
) : error ? (

Tactical Catalog Offline

{error}

) : filteredInventory.length === 0 ? (

No Supply Items Match

Adjust search criteria or add new items to the registry.

) : ( <> {pageData.map((item, idx) => ( { setSelectedItem(item); setShowDetailsModal(true); }} style={{ borderBottom: '1px solid rgba(255,255,255,0.05)', cursor: 'pointer', background: selectedItem?.id === item.id ? 'rgba(59, 130, 246, 0.05)' : 'transparent' }} className="hover-glow" > ))}
Item Name Category Min Threshold Max Level Supplier Details Lead Time Actions
{item.name}
{item.category}
{item.minStock} {item.unit}
{item.maxStock} {item.unit}
{item.supplierDetails}
{item.leadTimeDays} days
{/* Pagination Controls */}
Showing {filteredInventory.length === 0 ? 0 : (safePage - 1) * itemsPerPage + 1}–{Math.min(safePage * itemsPerPage, filteredInventory.length)} of {filteredInventory.length} items
Rows per page:
{Array.from({ length: totalPages }, (_, i) => i + 1) .filter(p => p === 1 || p === totalPages || Math.abs(p - safePage) <= 1) .map((p, i, arr) => ( {i > 0 && arr[i - 1] !== p - 1 && ...} ))}
)}
{/* Supply Details Modal */} {showDetailsModal && selectedItem && (
{/* Header */}

{selectedItem.name}

{selectedItem.category}
{/* Metrics */}
STOCK GAP
{selectedItem.totalStock - selectedItem.minStock} {selectedItem.unit}
REORDER POINT
{selectedItem.minStock} {selectedItem.unit}
{/* Supplier Card */}

Supplier & Logistics

Distributor {selectedItem.supplierDetails}
Procurement Lead Time {selectedItem.leadTimeDays} days
Target Max Level {selectedItem.maxStock} {selectedItem.unit}
{/* Vehicles Card */}

Ambulance Stock Distribution

{selectedItem.vehicles.length === 0 ? (
No active vehicle allocations found.
) : ( selectedItem.vehicles.map((v, i) => (
{v.vehicleId}
{v.stock} {selectedItem.unit}
)) )}
)} {/* Register Supply Item Modal */} {showAddModal && (

Register Supply Item

Inventory Master registry
{submitError && (
{submitError}
)}
{/* Column 1 */}
{metadata.commonNames[formCategory]?.length > 0 && (
)}
{formNameType === 'standard' && metadata.commonNames[formCategory]?.length > 0 ? ( ) : ( setFormNameCustom(e.target.value)} style={{ background: '#F8FAFC', border: '1px solid #E2E8F0', borderRadius: '10px', padding: '10px 14px', color: '#0F172A', fontSize: '0.85rem', outline: 'none', width: '100%', boxSizing: 'border-box' }} /> )}
{/* Column 2 */}
setFormMinStock(Number(e.target.value))} style={{ background: '#F8FAFC', border: '1px solid #E2E8F0', borderRadius: '10px', padding: '10px 14px', color: '#0F172A', fontSize: '0.85rem', outline: 'none', width: '100%', boxSizing: 'border-box' }} />
setFormMaxStock(Number(e.target.value))} style={{ background: '#F8FAFC', border: '1px solid #E2E8F0', borderRadius: '10px', padding: '10px 14px', color: '#0F172A', fontSize: '0.85rem', outline: 'none', width: '100%', boxSizing: 'border-box' }} />
setFormSupplier(e.target.value)} style={{ background: '#F8FAFC', border: '1px solid #E2E8F0', borderRadius: '10px', padding: '10px 14px', color: '#0F172A', fontSize: '0.85rem', outline: 'none', width: '100%', boxSizing: 'border-box' }} />
setFormLeadTime(Number(e.target.value))} style={{ background: '#F8FAFC', border: '1px solid #E2E8F0', borderRadius: '10px', padding: '10px 14px', color: '#0F172A', fontSize: '0.85rem', outline: 'none', width: '100%', boxSizing: 'border-box' }} />
)} {/* Edit Supply Item Modal */} {showEditModal && (

Edit Supply Item

UPDATE STOCK CATALOG
{editSubmitError && (
{editSubmitError}
)}
{/* Column 1 */}
setFormEditName(e.target.value)} style={{ background: '#F8FAFC', border: '1px solid #E2E8F0', borderRadius: '10px', padding: '10px 14px', color: '#0F172A', fontSize: '0.85rem', outline: 'none', width: '100%', boxSizing: 'border-box' }} />
{/* Column 2 */}
setFormEditMinStock(Number(e.target.value))} style={{ background: '#F8FAFC', border: '1px solid #E2E8F0', borderRadius: '10px', padding: '10px 14px', color: '#0F172A', fontSize: '0.85rem', outline: 'none', width: '100%', boxSizing: 'border-box' }} />
setFormEditMaxStock(Number(e.target.value))} style={{ background: '#F8FAFC', border: '1px solid #E2E8F0', borderRadius: '10px', padding: '10px 14px', color: '#0F172A', fontSize: '0.85rem', outline: 'none', width: '100%', boxSizing: 'border-box' }} />
setFormEditSupplier(e.target.value)} style={{ background: '#F8FAFC', border: '1px solid #E2E8F0', borderRadius: '10px', padding: '10px 14px', color: '#0F172A', fontSize: '0.85rem', outline: 'none', width: '100%', boxSizing: 'border-box' }} />
setFormEditLeadTime(Number(e.target.value))} style={{ background: '#F8FAFC', border: '1px solid #E2E8F0', borderRadius: '10px', padding: '10px 14px', color: '#0F172A', fontSize: '0.85rem', outline: 'none', width: '100%', boxSizing: 'border-box' }} />
)} {/* Single Restock Modal */} {showSingleRestockModal && selectedItem && (

Restock Supply Item

Single intake replenishing
{singleRestockError && (
{singleRestockError}
)}
{selectedItem.totalStock} {selectedItem.unit}
setSingleRestockQuantity(Number(e.target.value))} style={{ background: '#F8FAFC', border: '1px solid #E2E8F0', borderRadius: '10px', padding: '10px 14px', color: '#0F172A', fontSize: '0.85rem', outline: 'none', width: '100%', boxSizing: 'border-box', fontWeight: 700 }} />
)}
); };