/**
* БЛОК ДЕТАЛЬНОГО КАТАЛОГА С РЕЦЕПТУРОЙ
*
* Выделен из create-suppliers-supply-page.tsx
* Детальный просмотр товаров с настройкой рецептуры и панелью управления
*/
'use client'
import { Package, Settings, Building2 } from 'lucide-react'
import Image from 'next/image'
import { Badge } from '@/components/ui/badge'
import { DatePicker } from '@/components/ui/date-picker'
import { Input } from '@/components/ui/input'
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
import type {
DetailedCatalogBlockProps,
GoodsProduct,
ProductRecipe,
FulfillmentService,
FulfillmentConsumable,
SellerConsumable,
} from '../types/supply-creation.types'
export function DetailedCatalogBlock({
allSelectedProducts,
productRecipes,
fulfillmentServices,
fulfillmentConsumables,
sellerConsumables,
deliveryDate,
selectedFulfillment,
allCounterparties,
onQuantityChange,
onRecipeChange,
onDeliveryDateChange,
onFulfillmentChange,
onProductRemove,
}: DetailedCatalogBlockProps) {
const fulfillmentCenters = allCounterparties?.filter((partner) => partner.type === 'FULFILLMENT') || []
return (
{/* Панель управления */}
3. Настройки поставки
{/* Дата поставки */}
{
if (date) {
onDeliveryDateChange(date.toISOString().split('T')[0])
}
}}
className="w-full"
/>
{/* Фулфилмент-центр */}
{/* Каталог товаров с рецептурой */}
Товары в поставке ({allSelectedProducts.length})
{allSelectedProducts.length === 0 ? (
Товары не добавлены
Выберите товары из каталога выше для настройки рецептуры
) : (
{allSelectedProducts.map((product) => {
const recipe = productRecipes[product.id]
const selectedServicesIds = recipe?.selectedServices || []
const selectedFFConsumablesIds = recipe?.selectedFFConsumables || []
const selectedSellerConsumablesIds = recipe?.selectedSellerConsumables || []
return (
)
})}
)}
)
}
// Компонент детальной карточки товара с рецептурой
interface ProductDetailCardProps {
product: GoodsProduct & { selectedQuantity: number }
recipe?: ProductRecipe
fulfillmentServices: FulfillmentService[]
fulfillmentConsumables: FulfillmentConsumable[]
sellerConsumables: SellerConsumable[]
selectedServicesIds: string[]
selectedFFConsumablesIds: string[]
selectedSellerConsumablesIds: string[]
onQuantityChange: (productId: string, quantity: number) => void
onRecipeChange: (productId: string, recipe: ProductRecipe) => void
onRemove: (productId: string) => void
}
function ProductDetailCard({
product,
selectedServicesIds,
selectedFFConsumablesIds,
selectedSellerConsumablesIds,
fulfillmentServices,
fulfillmentConsumables,
sellerConsumables,
onQuantityChange,
onRemove,
}: ProductDetailCardProps) {
return (
{/* 1. ИЗОБРАЖЕНИЕ ТОВАРА (фиксированная ширина) */}
{product.mainImage || (product.images && product.images[0]) ? (
) : (
)}
{/* 2. ОСНОВНАЯ ИНФОРМАЦИЯ (flex-1) */}
{product.name}
{product.article &&
Арт: {product.article}
}
{product.category?.name && (
{product.category.name}
)}
{product.price.toLocaleString('ru-RU')} ₽/{product.unit || 'шт'}
{/* 3. КОЛИЧЕСТВО/СУММА/ОСТАТОК (flex-1) */}
{product.quantity !== undefined && (
0 ? 'bg-green-400' : 'bg-red-400'}`} />
0 ? 'text-green-400' : 'text-red-400'}`}>
{product.quantity > 0 ? `${product.quantity} шт` : 'Нет в наличии'}
)}
{
const inputValue = e.target.value
const newQuantity = inputValue === '' ? 0 : Math.max(0, parseInt(inputValue) || 0)
onQuantityChange(product.id, newQuantity)
}}
className="glass-input w-16 h-8 text-sm text-center text-white placeholder:text-white/50"
placeholder="0"
/>
шт
{(product.price * product.selectedQuantity).toLocaleString('ru-RU')} ₽
{/* 4-7. КОМПОНЕНТЫ РЕЦЕПТУРЫ */}
)
}
// Компонент компонентов рецептуры (услуги + расходники + WB карточка)
interface RecipeComponentsProps {
productId: string
selectedQuantity: number
selectedServicesIds: string[]
selectedFFConsumablesIds: string[]
selectedSellerConsumablesIds: string[]
fulfillmentServices: FulfillmentService[]
fulfillmentConsumables: FulfillmentConsumable[]
sellerConsumables: SellerConsumable[]
}
function RecipeComponents({
selectedServicesIds,
selectedFFConsumablesIds,
selectedSellerConsumablesIds,
fulfillmentServices,
fulfillmentConsumables,
sellerConsumables,
}: RecipeComponentsProps) {
return (
<>
{/* 4. УСЛУГИ ФФ (flex-1) */}
🛠️ Услуги ФФ
{fulfillmentServices.length > 0 ? (
fulfillmentServices.map((service) => {
const isSelected = selectedServicesIds.includes(service.id)
return (
)
})
) : (
Нет услуг
)}
{/* 5. РАСХОДНИКИ ФФ (flex-1) */}
📦 Расходники ФФ
{fulfillmentConsumables.length > 0 ? (
fulfillmentConsumables.map((consumable) => {
const isSelected = selectedFFConsumablesIds.includes(consumable.id)
return (
)
})
) : (
Загрузка...
)}
{/* 6. РАСХОДНИКИ СЕЛЛЕРА (flex-1) */}
🏪 Расходники сел.
{sellerConsumables.length > 0 ? (
sellerConsumables.map((consumable) => {
const isSelected = selectedSellerConsumablesIds.includes(consumable.id)
return (
)
})
) : (
Загрузка...
)}
{/* 7. МП + ИТОГО (flex-1) */}
{/* Здесь будет общая стоимость с рецептурой */}
>
)
}