import React, { useState, useEffect } from 'react'; import { Card, Descriptions, Button, Space, Tag, Image, Divider, Row, Col, Tabs, Table, Modal, message, Spin, Typography, Tooltip, Badge, } from 'antd'; import { ShoppingCartOutlined, EditOutlined, DeleteOutlined, CopyOutlined, HistoryOutlined, ShopOutlined, TagOutlined, DollarOutlined, BoxPlotOutlined, FileImageOutlined, CheckCircleOutlined, CloseCircleOutlined, SyncOutlined, } from '@ant-design/icons'; import type { ColumnsType } from 'antd/es/table'; import { productDataSource, Product } from '@/services/productDataSource'; const { Title, Text } = Typography; const { TabPane } = Tabs; interface ProductDetail { id: string; productId: string; platform: string; name: string; description: string; category: string; brand: string; status: 'DRAFT' | 'PENDING' | 'ACTIVE' | 'INACTIVE' | 'SUSPENDED'; price: number; costPrice: number; currency: string; stock: number; sku: string; images: string[]; attributes: Record; variants: ProductVariant[]; complianceStatus: 'COMPLIANT' | 'NON_COMPLIANT' | 'PENDING_REVIEW'; certificates: string[]; createdAt: string; updatedAt: string; publishedAt?: string; } interface ProductVariant { id: string; sku: string; name: string; price: number; stock: number; attributes: Record; } interface PriceHistory { id: string; price: number; currency: string; changedAt: string; changedBy: string; reason: string; } interface StockHistory { id: string; quantity: number; type: 'IN' | 'OUT'; reason: string; createdAt: string; } const MOCK_PRODUCT: ProductDetail = { id: '1', productId: 'P-2026-001', platform: 'Amazon', name: 'Industrial Temperature Sensor Pro', description: 'High-precision industrial temperature sensor with digital output. Suitable for manufacturing environments with temperature range -40°C to +125°C.', category: 'Industrial Automation > Sensors', brand: 'TechPro', status: 'ACTIVE', price: 89.99, costPrice: 45.00, currency: 'USD', stock: 256, sku: 'TP-TEMP-001', images: [ 'https://via.placeholder.com/400x400?text=Product+1', 'https://via.placeholder.com/400x400?text=Product+2', 'https://via.placeholder.com/400x400?text=Product+3', ], attributes: { 'Temperature Range': '-40°C to +125°C', 'Accuracy': '±0.5°C', 'Output Type': 'Digital (I2C)', 'Power Supply': '3.3V - 5V DC', 'Housing Material': 'Stainless Steel 316', 'IP Rating': 'IP67', }, variants: [ { id: 'v1', sku: 'TP-TEMP-001-A', name: 'Standard Cable 1m', price: 89.99, stock: 150, attributes: { 'Cable Length': '1m' } }, { id: 'v2', sku: 'TP-TEMP-001-B', name: 'Extended Cable 3m', price: 99.99, stock: 80, attributes: { 'Cable Length': '3m' } }, { id: 'v3', sku: 'TP-TEMP-001-C', name: 'Extended Cable 5m', price: 109.99, stock: 26, attributes: { 'Cable Length': '5m' } }, ], complianceStatus: 'COMPLIANT', certificates: ['CE', 'FCC', 'RoHS'], createdAt: '2025-12-15 10:00:00', updatedAt: '2026-03-18 14:30:00', publishedAt: '2025-12-20 09:00:00', }; const MOCK_PRICE_HISTORY: PriceHistory[] = [ { id: '1', price: 89.99, currency: 'USD', changedAt: '2026-03-18 14:30:00', changedBy: 'System', reason: 'Market price adjustment' }, { id: '2', price: 84.99, currency: 'USD', changedAt: '2026-02-01 10:00:00', changedBy: 'Admin', reason: 'Promotional pricing' }, { id: '3', price: 94.99, currency: 'USD', changedAt: '2025-12-20 09:00:00', changedBy: 'Admin', reason: 'Initial listing price' }, ]; const MOCK_STOCK_HISTORY: StockHistory[] = [ { id: '1', quantity: 50, type: 'IN', reason: 'Restock from supplier', createdAt: '2026-03-15 08:00:00' }, { id: '2', quantity: 25, type: 'OUT', reason: 'Order #ORD-2026-1234', createdAt: '2026-03-14 16:30:00' }, { id: '3', quantity: 100, type: 'IN', reason: 'Initial stock', createdAt: '2025-12-20 09:00:00' }, ]; const STATUS_CONFIG: Record = { DRAFT: { color: 'default', text: 'Draft' }, PENDING: { color: 'processing', text: 'Pending Review' }, ACTIVE: { color: 'success', text: 'Active' }, INACTIVE: { color: 'warning', text: 'Inactive' }, SUSPENDED: { color: 'error', text: 'Suspended' }, }; const COMPLIANCE_CONFIG: Record = { COMPLIANT: { color: 'success', icon: }, NON_COMPLIANT: { color: 'error', icon: }, PENDING_REVIEW: { color: 'warning', icon: }, }; export const ProductDetail: React.FC = () => { const [loading, setLoading] = useState(true); const [product, setProduct] = useState(null); const [priceHistory, setPriceHistory] = useState([]); const [stockHistory, setStockHistory] = useState([]); const [editModalVisible, setEditModalVisible] = useState(false); useEffect(() => { fetchProductDetail(); }, []); const fetchProductDetail = async () => { setLoading(true); await new Promise(resolve => setTimeout(resolve, 800)); setProduct(MOCK_PRODUCT); setPriceHistory(MOCK_PRICE_HISTORY); setStockHistory(MOCK_STOCK_HISTORY); setLoading(false); }; const handleEdit = () => { setEditModalVisible(true); }; const handleDelete = () => { Modal.confirm({ title: 'Delete Product', content: 'Are you sure you want to delete this product? This action cannot be undone.', okText: 'Delete', okType: 'danger', onOk: () => { message.success('Product deleted successfully'); }, }); }; const handleDuplicate = () => { message.success('Product duplicated. Redirecting to edit page...'); }; const handlePublish = () => { Modal.confirm({ title: 'Publish Product', content: 'Publish this product to all connected platforms?', onOk: () => { message.success('Product published successfully'); }, }); }; const priceColumns: ColumnsType = [ { title: 'Price', dataIndex: 'price', key: 'price', render: (v, r) => `${r.currency} ${v.toFixed(2)}` }, { title: 'Changed At', dataIndex: 'changedAt', key: 'changedAt' }, { title: 'Changed By', dataIndex: 'changedBy', key: 'changedBy' }, { title: 'Reason', dataIndex: 'reason', key: 'reason' }, ]; const stockColumns: ColumnsType = [ { title: 'Type', dataIndex: 'type', key: 'type', render: (type: string) => ( {type === 'IN' ? 'Stock In' : 'Stock Out'} ) }, { title: 'Quantity', dataIndex: 'quantity', key: 'quantity' }, { title: 'Reason', dataIndex: 'reason', key: 'reason' }, { title: 'Date', dataIndex: 'createdAt', key: 'createdAt' }, ]; const variantColumns: ColumnsType = [ { title: 'SKU', dataIndex: 'sku', key: 'sku' }, { title: 'Name', dataIndex: 'name', key: 'name' }, { title: 'Price', dataIndex: 'price', key: 'price', render: (v) => `USD ${v.toFixed(2)}` }, { title: 'Stock', dataIndex: 'stock', key: 'stock', render: (stock: number) => ( 50 ? '#52c41a' : stock > 10 ? '#faad14' : '#ff4d4f' }} /> ) }, ]; if (loading) { return (
); } if (!product) { return
Product not found
; } const profitMargin = ((product.price - product.costPrice) / product.price * 100).toFixed(1); const statusConfig = STATUS_CONFIG[product.status]; const complianceConfig = COMPLIANCE_CONFIG[product.complianceStatus]; return (
{product.name}
{product.images.slice(1).map((img, idx) => ( ))}
{product.images.map((img, idx) => ( ))}
{product.platform} {statusConfig.text} {product.complianceStatus.replace('_', ' ')} {product.name} SKU: {product.sku} | ID: {product.productId}
{product.category} {product.brand} Price}> {product.currency} {product.price.toFixed(2)} {product.currency} {product.costPrice.toFixed(2)} = 30 ? 'green' : parseFloat(profitMargin) >= 15 ? 'orange' : 'red'}> {profitMargin}% Stock}> 50 ? '#52c41a' : product.stock > 10 ? '#faad14' : '#ff4d4f' }} />
Certificates: {product.certificates.map(cert => ( } color="green">{cert} ))}
{product.description} {Object.entries(product.attributes).map(([key, value]) => ( {value} ))} Price History} key="priceHistory">
Stock History} key="stockHistory">
setEditModalVisible(false)} footer={null} width={800} >

Edit form will be implemented here...

); }; export default ProductDetail;