import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import { Edit, Trash, AlertTriangle, CheckCircle, AlertCircle } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Product } from "@/models/products"; import { Badge } from "@/components/ui/badge"; import { Switch } from "@/components/ui/switch"; interface ProductTableProps { products: Product[]; loading: boolean; onEdit: (product: Product) => void; onDelete: (productId: string) => void; onToggleEnabled: (productId: string, enabled: boolean) => void; getCategoryNameById: (categoryId: string) => string; } const ProductTable = ({ products, loading, onEdit, onDelete, onToggleEnabled, getCategoryNameById }: ProductTableProps) => { const sortedProducts = [...products].sort((a, b) => { const categoryNameA = getCategoryNameById(a.category); const categoryNameB = getCategoryNameById(b.category); return categoryNameA.localeCompare(categoryNameB); }); const getStockIcon = (product: Product) => { if (!product.stockTracking) return null; if (product.stockStatus === 'out_of_stock') { return ; } else if (product.stockStatus === 'low_stock') { return ; } else { return ; } }; return (
Product Category Unit Stock Enabled Actions {loading ? ( Array.from({ length: 1 }).map((_, index) => ( Loading... Loading... Loading... Loading... Loading... Loading... )) ) : sortedProducts.length > 0 ? ( sortedProducts.map((product) => (
{product.name}
{getCategoryNameById(product.category)} {product.unitType} {product.stockTracking ? (
{getStockIcon(product)} {product.currentStock !== undefined ? product.currentStock : 0} {product.unitType}
) : ( Not Tracked )}
onToggleEnabled(product._id as string, checked)} />
)) ) : ( No products found. )}
); }; export default ProductTable;