import React, { useState, useEffect } from 'react'; import { Button } from '../ui/button'; import { SearchInput } from '../ui/input'; import { EquipmentCard } from './EquipmentCard'; import { GearItem } from '../../types'; import { Plus, Filter, Download, Box, Loader2 } from 'lucide-react'; import { useToast } from '../../context/ToastContext'; import { gearService } from '../../services/gearService'; import { logger } from '@/utils/logger'; interface InventoryViewProps { onNavigate: (view: string, id?: string) => void; } export const InventoryView: React.FC = ({ onNavigate }) => { const { addToast } = useToast(); const [search, setSearch] = useState(''); const [filterCat, setFilterCat] = useState('All'); const [filterStatus, setFilterStatus] = useState('All'); const [inventory, setInventory] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { loadInventory(); }, []); const loadInventory = async () => { try { setLoading(true); const data = await gearService.list(); setInventory(data); } catch (e) { logger.error('Failed to load gear', { error: e instanceof Error ? e.message : String(e), stack: e instanceof Error ? e.stack : undefined, }); } finally { setLoading(false); } }; const filteredItems = inventory.filter((item) => { const matchSearch = item.name.toLowerCase().includes(search.toLowerCase()) || item.brand.toLowerCase().includes(search.toLowerCase()); const matchCat = filterCat === 'All' || item.category === filterCat; const matchStatus = filterStatus === 'All' || item.status === filterStatus; return matchSearch && matchCat && matchStatus; }); return (
{/* Header */}

GEAR INVENTORY

Track hardware, warranties, and maintenance.

{/* Filters */}
setSearch(e.target.value)} />
{/* Grid */} {loading ? (
) : (
{filteredItems.map((item) => ( onNavigate('inventory/detail', item.id)} /> ))} {filteredItems.length === 0 && (

No equipment found.

)}
)}
); };