"use client" import { useState } from 'react' import { useQuery } from '@apollo/client' import { Card } from '@/components/ui/card' import { Button } from '@/components/ui/button' import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog' import { Sidebar } from '@/components/dashboard/sidebar' import { ProductForm } from './product-form' import { ProductCard } from './product-card' import { GET_MY_PRODUCTS } from '@/graphql/queries' import { Plus, Search, Package } from 'lucide-react' import { Input } from '@/components/ui/input' interface Product { id: string name: string article: string description: string price: number quantity: number category: { id: string; name: string } | null brand: string color: string size: string weight: number dimensions: string material: string images: string[] mainImage: string isActive: boolean createdAt: string updatedAt: string } export function WarehouseDashboard() { const [isDialogOpen, setIsDialogOpen] = useState(false) const [editingProduct, setEditingProduct] = useState(null) const [searchQuery, setSearchQuery] = useState('') const { data, loading, error, refetch } = useQuery(GET_MY_PRODUCTS, { errorPolicy: 'all' }) const products: Product[] = data?.myProducts || [] // Фильтрация товаров по поисковому запросу const filteredProducts = products.filter(product => product.name.toLowerCase().includes(searchQuery.toLowerCase()) || product.article.toLowerCase().includes(searchQuery.toLowerCase()) || product.category?.name?.toLowerCase().includes(searchQuery.toLowerCase()) || product.brand?.toLowerCase().includes(searchQuery.toLowerCase()) ) const handleCreateProduct = () => { setEditingProduct(null) setIsDialogOpen(true) } const handleEditProduct = (product: Product) => { setEditingProduct(product) setIsDialogOpen(true) } const handleProductSaved = () => { setIsDialogOpen(false) setEditingProduct(null) refetch() } const handleProductDeleted = () => { refetch() } if (error) { return (

Ошибка загрузки

{error.message || 'Не удалось загрузить товары'}

) } return (
{/* Заголовок и поиск */}

Склад товаров

Управление ассортиментом вашего склада

{editingProduct ? 'Редактировать товар' : 'Добавить новый товар'} setIsDialogOpen(false)} />
{/* Поиск */}
setSearchQuery(e.target.value)} className="glass-input text-white placeholder:text-white/50 pl-10 h-10" />
{/* Основной контент */} {loading ? (

Загрузка товаров...

) : filteredProducts.length === 0 ? (

{searchQuery ? 'Товары не найдены' : 'Склад пуст'}

{searchQuery ? 'Попробуйте изменить критерии поиска' : 'Добавьте ваш первый товар на склад' }

{!searchQuery && ( )}
) : (
{filteredProducts.map((product) => ( ))}
)}
) }