import React, { useState } from 'react'; import { X, Save, AlertCircle, CheckCircle, DownloadCloud, Plus, Box } from 'lucide-react'; import { CatalogueProduct, ImportCatalogueProductRequest } from '../services/catalogueApi'; import { useProductSubcategories, useTenantCategories } from '../hooks/useCatalogueImport'; import { SlideDrawer } from './consoleUi'; import FMCGHoverOverlay from './FMCGHoverOverlay'; interface ImportProductModalProps { product: CatalogueProduct; tenantid: number; locationid: number; onClose: () => void; onImport: (item: ImportCatalogueProductRequest) => void; isImported?: boolean; } export default function ImportProductModal({ product, tenantid, locationid, onClose, onImport, isImported = false }: ImportProductModalProps) { const [categoryId, setCategoryId] = useState(''); const [subcategoryId, setSubcategoryId] = useState(''); const [retailPrice, setRetailPrice] = useState(''); const [productCost, setProductCost] = useState(''); const [taxPercent, setTaxPercent] = useState('0'); const [quantity, setQuantity] = useState('1'); // Categories this tenant's own products actually use const { data: categories = [], isLoading: isLoadingCategories } = useTenantCategories(tenantid); // Subcategories scoped to selected category const { data: subcategories = [], isLoading: isLoadingSubcats } = useProductSubcategories( tenantid, categoryId ? Number(categoryId) : undefined, ); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); if (!categoryId || !retailPrice || !productCost) { alert("Please fill in all required fields."); return; } onImport({ tenantid, locationid, brand: product.brand, catalogueid: product.id, categoryid: Number(categoryId), subcategoryid: subcategoryId ? Number(subcategoryId) : 0, quantity: Number(quantity), stocktype: "in", // Draft: lands in the Admin Catalogue only, published to the store // catalogue separately via the explicit "Add to Store Catalogue" step. status: "Draft", retailprice: Number(retailPrice), productcost: Number(productCost), taxpercent: Number(taxPercent), }); }; return (
{/* Clean Image Container */}
{product.images && product.images.length > 0 ? ( {product.product_name} ) : ( )} {isImported && (
In Store Catalogue
)}
{/* Title & Basics */}

ID: {product.id}

{product.product_name}

{product.brand.replace('brand_', '')}
{/* Price Range Container */}
Price Range
{product.price_range || 'N/A'}
{product.size && ( Size: {product.size} )}
{/* Import Action Container */}
{isImported ? (
Imported

This product is available in your Admin Catalogue. Set pricing and store parameters in the Admin Catalogue.

) : (

Import Product

Global FMCG

Import this product to your Admin Catalogue. Selling price and outlet parameters will be managed directly in your Admin Catalogue.

)}
{/* Retail Packaging Details */}

Retail Packaging Info

); }