'use client' import { ArrowLeft, Info } from 'lucide-react' import React from 'react' import { Sidebar } from '@/components/dashboard/sidebar' import { Button } from '@/components/ui/button' import { useSidebar } from '@/hooks/useSidebar' import { CartSummary } from './cart-summary' import { FloatingCart } from './floating-cart' import { ProductGrid } from './product-grid' import { SupplierForCreation, SupplierProduct, SelectedProduct } from './types' interface SupplierProductsPageProps { selectedSupplier: SupplierForCreation products: SupplierProduct[] selectedProducts: SelectedProduct[] onQuantityChange: (productId: string, quantity: number) => void onBack: () => void onCreateSupply: () => void formatCurrency: (amount: number) => string showSummary: boolean setShowSummary: (show: boolean) => void loading: boolean } export function SupplierProductsPage({ selectedSupplier, products, selectedProducts, onQuantityChange, onBack, onCreateSupply, formatCurrency, showSummary, setShowSummary, loading, }: SupplierProductsPageProps) { const { getSidebarMargin } = useSidebar() const getSelectedQuantity = (productId: string): number => { const selected = selectedProducts.find((p) => p.id === productId && p.supplierId === selectedSupplier.id) return selected ? selected.selectedQuantity : 0 } const selectedProductsMap = products.reduce( (acc, product) => { acc[product.id] = getSelectedQuantity(product.id) return acc }, {} as Record, ) const getTotalAmount = () => { return selectedProducts.reduce((sum, product) => { const discountedPrice = product.discount ? product.price * (1 - product.discount / 100) : product.price return sum + discountedPrice * product.selectedQuantity }, 0) } const getTotalItems = () => { return selectedProducts.reduce((sum, product) => sum + product.selectedQuantity, 0) } const handleRemoveProduct = (productId: string, supplierId: string) => { onQuantityChange(productId, 0) } const handleCartQuantityChange = (productId: string, supplierId: string, quantity: number) => { onQuantityChange(productId, quantity) } return (

Товары поставщика

{selectedSupplier.name} • {products.length} товаров

setShowSummary(false)} formatCurrency={formatCurrency} visible={showSummary && selectedProducts.length > 0} /> setShowSummary(!showSummary)} visible={selectedProducts.length > 0 && !showSummary} />
) }