"use client"

import React from 'react'
import { ProductCard } from './product-card'
import { Package } from 'lucide-react'
import { WholesalerProduct } from './types'

interface ProductGridProps {
  products: WholesalerProduct[]
  selectedProducts: Record<string, number>
  onQuantityChange: (productId: string, quantity: number) => void
  formatCurrency: (amount: number) => string
  loading?: boolean
}

export function ProductGrid({ 
  products, 
  selectedProducts, 
  onQuantityChange, 
  formatCurrency,
  loading = false
}: ProductGridProps) {
  if (loading) {
    return (
      <div className="flex items-center justify-center p-8">
        <div className="text-center">
          <div className="animate-spin rounded-full h-12 w-12 border-4 border-white border-t-transparent mx-auto mb-4"></div>
          <p className="text-white/60">Загружаем товары...</p>
        </div>
      </div>
    )
  }

  if (products.length === 0) {
    return (
      <div className="flex items-center justify-center p-8">
        <div className="text-center">
          <Package className="h-12 w-12 text-white/20 mx-auto mb-4" />
          <p className="text-white/60">У этого оптовика нет товаров</p>
          <p className="text-white/40 text-sm mt-2">Выберите другого оптовика</p>
        </div>
      </div>
    )
  }

  return (
    <div className="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-4">
      {products.map((product) => (
        <ProductCard
          key={product.id}
          product={product}
          selectedQuantity={selectedProducts[product.id] || 0}
          onQuantityChange={(quantity) => onQuantityChange(product.id, quantity)}
          formatCurrency={formatCurrency}
        />
      ))}
    </div>
  )
} 