"use client" import React, { useState } from 'react' import { Card } from '@/components/ui/card' import { Button } from '@/components/ui/button' import { Badge } from '@/components/ui/badge' import { Input } from '@/components/ui/input' import { ArrowLeft, Package, Plus, Minus, ShoppingCart, Eye, Info } from 'lucide-react' import Image from 'next/image' interface Wholesaler { id: string inn: string name: string fullName: string address: string phone?: string email?: string rating: number productCount: number avatar?: string specialization: string[] } interface Product { id: string name: string article: string description: string price: number quantity: number category: string brand?: string color?: string size?: string weight?: number dimensions?: string material?: string images: string[] mainImage?: string } interface SelectedProduct extends Product { selectedQuantity: number } interface WholesalerProductsProps { wholesaler: Wholesaler onBack: () => void onClose: () => void onSupplyCreated: () => void } // Моковые данные товаров const mockProducts: Product[] = [ { id: '1', name: 'Смартфон Samsung Galaxy A54', article: 'SGX-A54-128', description: 'Смартфон с экраном 6.4", камерой 50 МП, 128 ГБ памяти', price: 28900, quantity: 150, category: 'Смартфоны', brand: 'Samsung', color: 'Черный', size: '6.4"', weight: 202, dimensions: '158.2 x 76.7 x 8.2 мм', material: 'Алюминий, стекло', images: ['/api/placeholder/300/300?text=Samsung+A54'], mainImage: '/api/placeholder/300/300?text=Samsung+A54' }, { id: '2', name: 'Наушники Sony WH-1000XM4', article: 'SNY-WH1000XM4', description: 'Беспроводные наушники с шумоподавлением', price: 24900, quantity: 85, category: 'Наушники', brand: 'Sony', color: 'Черный', weight: 254, material: 'Пластик, кожа', images: ['/api/placeholder/300/300?text=Sony+WH1000XM4'], mainImage: '/api/placeholder/300/300?text=Sony+WH1000XM4' }, { id: '3', name: 'Планшет iPad Air 10.9"', article: 'APL-IPADAIR-64', description: 'Планшет Apple iPad Air с чипом M1, 64 ГБ', price: 54900, quantity: 45, category: 'Планшеты', brand: 'Apple', color: 'Серый космос', size: '10.9"', weight: 461, dimensions: '247.6 x 178.5 x 6.1 мм', material: 'Алюминий', images: ['/api/placeholder/300/300?text=iPad+Air'], mainImage: '/api/placeholder/300/300?text=iPad+Air' }, { id: '4', name: 'Ноутбук Lenovo ThinkPad E15', article: 'LNV-TE15-I5', description: 'Ноутбук 15.6" Intel Core i5, 8 ГБ ОЗУ, 256 ГБ SSD', price: 45900, quantity: 25, category: 'Ноутбуки', brand: 'Lenovo', color: 'Черный', size: '15.6"', weight: 1700, dimensions: '365 x 240 x 19.9 мм', material: 'Пластик', images: ['/api/placeholder/300/300?text=ThinkPad+E15'], mainImage: '/api/placeholder/300/300?text=ThinkPad+E15' }, { id: '5', name: 'Умные часы Apple Watch SE', article: 'APL-AWSE-40', description: 'Умные часы Apple Watch SE 40 мм', price: 21900, quantity: 120, category: 'Умные часы', brand: 'Apple', color: 'Белый', size: '40 мм', weight: 30, dimensions: '40 x 34 x 10.7 мм', material: 'Алюминий', images: ['/api/placeholder/300/300?text=Apple+Watch+SE'], mainImage: '/api/placeholder/300/300?text=Apple+Watch+SE' }, { id: '6', name: 'Клавиатура Logitech MX Keys', article: 'LGT-MXKEYS', description: 'Беспроводная клавиатура для продуктивной работы', price: 8900, quantity: 75, category: 'Клавиатуры', brand: 'Logitech', color: 'Графит', weight: 810, dimensions: '430.2 x 20.5 x 131.6 мм', material: 'Пластик, металл', images: ['/api/placeholder/300/300?text=MX+Keys'], mainImage: '/api/placeholder/300/300?text=MX+Keys' } ] export function WholesalerProducts({ wholesaler, onBack, onClose, onSupplyCreated }: WholesalerProductsProps) { const [selectedProducts, setSelectedProducts] = useState([]) const [showSummary, setShowSummary] = useState(false) const formatCurrency = (amount: number) => { return new Intl.NumberFormat('ru-RU', { style: 'currency', currency: 'RUB', minimumFractionDigits: 0 }).format(amount) } const updateProductQuantity = (productId: string, quantity: number) => { const product = mockProducts.find(p => p.id === productId) if (!product) return setSelectedProducts(prev => { const existing = prev.find(p => p.id === productId) if (quantity === 0) { // Удаляем продукт если количество 0 return prev.filter(p => p.id !== productId) } if (existing) { // Обновляем количество существующего продукта return prev.map(p => p.id === productId ? { ...p, selectedQuantity: quantity } : p ) } else { // Добавляем новый продукт return [...prev, { ...product, selectedQuantity: quantity }] } }) } const getSelectedQuantity = (productId: string): number => { const selected = selectedProducts.find(p => p.id === productId) return selected ? selected.selectedQuantity : 0 } const getTotalAmount = () => { return selectedProducts.reduce((sum, product) => sum + (product.price * product.selectedQuantity), 0 ) } const getTotalItems = () => { return selectedProducts.reduce((sum, product) => sum + product.selectedQuantity, 0) } const handleCreateSupply = () => { console.log('Создание поставки с товарами:', selectedProducts) // TODO: Здесь будет реальное создание поставки onSupplyCreated() } return (

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

{wholesaler.name} • {mockProducts.length} товаров

{showSummary && selectedProducts.length > 0 && (

Резюме заказа

{selectedProducts.map((product) => (
{product.name} × {product.selectedQuantity}
{formatCurrency(product.price * product.selectedQuantity)}
))}
Итого: {getTotalItems()} товаров {formatCurrency(getTotalAmount())}
)}
{mockProducts.map((product) => { const selectedQuantity = getSelectedQuantity(product.id) return (
{product.name}
В наличии: {product.quantity}

{product.name}

Артикул: {product.article}

{product.category} {product.brand && ( {product.brand} )}

{product.description}

{product.color && (
Цвет: {product.color}
)} {product.size && (
Размер: {product.size}
)} {product.weight && (
Вес: {product.weight} г
)}
{formatCurrency(product.price)}
за штуку
{ const value = Math.max(0, Math.min(product.quantity, parseInt(e.target.value) || 0)) updateProductQuantity(product.id, value) }} className="h-8 w-16 text-center bg-white/10 border-white/20 text-white" min={0} max={product.quantity} />
{selectedQuantity > 0 && (
Сумма: {formatCurrency(product.price * selectedQuantity)}
)}
) })}
{selectedProducts.length > 0 && (
)}
) }