// New order builder — smart search with live results, quick-add, running cart
function NewOrderScreen({ vendedora, draft, onAddProduct, onUpdateQty, onRemove, onConfirm, onBack, onOpenScan }) {
const T = window.T;
const { Icon, ProductTile } = window;
const [query, setQuery] = React.useState('');
const [catalogoFilter, setCatalogoFilter] = React.useState('Todos');
const [selected, setSelected] = React.useState(null); // product obj being added
const [qty, setQty] = React.useState(1);
const filtered = React.useMemo(() => {
const q = query.trim().toLowerCase();
return window.CATALOGO_DATA.filter(p => {
if (catalogoFilter !== 'Todos' && p.catalogo !== catalogoFilter) return false;
if (!q) return false;
return p.codigo.includes(q) || p.nombre.toLowerCase().includes(q) || p.descripcion.toLowerCase().includes(q);
}).slice(0, 8);
}, [query, catalogoFilter]);
// quick-add chips — most used codes
const quickCodes = ['40821', '32207', '20618', '55031'];
const quickItems = quickCodes.map(c => window.CATALOGO_DATA.find(p => p.codigo === c)).filter(Boolean);
const total = draft.reduce((s, p) => s + p.precio * p.cantidad, 0);
const items = draft.reduce((s, p) => s + p.cantidad, 0);
const handlePick = (prod) => { setSelected(prod); setQty(1); };
const handleAddSelected = () => {
if (!selected) return;
onAddProduct({
id: Date.now(), codigo: selected.codigo, catalogo: selected.catalogo,
nombre: selected.nombre, descripcion: selected.descripcion,
precio: selected.precio, cantidad: qty, empaque: selected.tipo, tono: selected.tono,
imagen: selected.imagen,
});
setSelected(null); setQuery(''); setQty(1);
};
return (
{/* Header */}
Borrador · {vendedora?.zona}
{/* Search row */}
{/* Catalog filter chips */}
{['Todos', ...window.CATALOGOS].map(c => (
))}
{/* Scrollable body */}
0 ? 140 : 40 }}>
{/* Search results */}
{query.trim() ? (
{filtered.length === 0 ? (
Sin resultados
Revisa el código o cambia de catálogo
) : (
{filtered.map(p => (
))}
)}
) : (
<>
{/* Quick add */}
{quickItems.map(p => (
))}
{/* Current draft items */}
{draft.length > 0 && (
{draft.map(p => (
{p.codigo} · {p.catalogo}
{p.nombre}
{/* stepper */}
{p.cantidad}
))}
)}
>
)}
{/* Floating confirm bar */}
{draft.length > 0 && (
)}
{/* Product picker sheet (after selecting from search) */}
{selected && (
setSelected(null)}>
e.stopPropagation()} style={{
width: '100%', background: T.paper, borderRadius: '28px 28px 0 0',
padding: '12px 24px 32px',
}}>
{selected.codigo} · {selected.catalogo} · pág. {selected.pagina}
{selected.nombre}
{selected.descripcion}
Precio unitario
${selected.precio.toFixed(2)}
{qty}
Agregar al pedido · ${(selected.precio * qty).toFixed(2)}
)}
);
}
window.NewOrderScreen = NewOrderScreen;