import { useState } from 'react'; import { RotateCcw, Save, X } from 'lucide-react'; import { CUT_FAMILY_RULES, type CutFamilyKey } from '../analytics/cutting'; import { editableProductTypeOptions, getProductTypeConfig, resolveProductType, type ProductTypeKey } from '../productClassification'; import type { CutProductOverride } from '../types'; import ProductTypeBadge from './ProductTypeBadge'; type SkuPlanningModalProduct = { id: string; name: string; color?: string; size?: string; }; type SkuPlanningModalProps = { product: SkuPlanningModalProduct; override?: CutProductOverride; isSaving?: boolean; onClose: () => void; onSave: (override: CutProductOverride | null) => void | Promise; }; const familyOptions: Array<{ value: CutFamilyKey | ''; label: string }> = [ { value: '', label: 'Auto' }, ...CUT_FAMILY_RULES.map(rule => ({ value: rule.key, label: `${rule.materialLabel} · ${rule.label}` })), { value: 'OUTROS', label: 'Sem regra' } ]; const buildOverride = ({ familyKey, color, size, productType, planningNotes }: Required> & { familyKey: CutFamilyKey | ''; productType: ProductTypeKey | ''; }): CutProductOverride | null => { const next: CutProductOverride = { familyKey, color: color.trim(), size: size.trim().toUpperCase(), productType, planningNotes: planningNotes.trim() }; if (!next.familyKey && !next.color && !next.size && !next.productType && !next.planningNotes) { return null; } return next; }; const SkuPlanningModal = ({ product, override, isSaving = false, onClose, onSave }: SkuPlanningModalProps) => { const [familyKey, setFamilyKey] = useState(override?.familyKey || ''); const [color, setColor] = useState(override?.color || ''); const [size, setSize] = useState(override?.size || ''); const [productType, setProductType] = useState(override?.productType || ''); const [planningNotes, setPlanningNotes] = useState(override?.planningNotes || ''); const resolvedType = resolveProductType(product.name, { productType }); const resolvedConfig = getProductTypeConfig(resolvedType); const handleSave = () => { void onSave(buildOverride({ familyKey, color, size, productType, planningNotes })); }; const handleClear = () => { void onSave(null); }; return (
event.stopPropagation()} >
SKU #{product.id}

{product.name}

{resolvedConfig.description}