// SelectionPanel.jsx — right drawer listing the selected wines. // View, remove individually, clear all, and reorder via drag & drop. // The order here defines the order of the generated PDF. const { useState: useSelState, useRef: useSelRef } = React; const SelectionPanel = ({ open, wines, onClose, onRemove, onClear, onReorder, onGenerate }) => { const [dragIndex, setDragIndex] = useSelState(null); const [overIndex, setOverIndex] = useSelState(null); React.useEffect(() => { const fn = (e) => { if (e.key === 'Escape') onClose(); }; if (open) window.addEventListener('keydown', fn); return () => window.removeEventListener('keydown', fn); }, [open, onClose]); if (!open) return null; const handleDrop = (to) => { if (dragIndex === null || dragIndex === to) { setDragIndex(null); setOverIndex(null); return; } const ids = wines.map((w) => w.id); const [moved] = ids.splice(dragIndex, 1); ids.splice(to, 0, moved); onReorder(ids); setDragIndex(null); setOverIndex(null); }; return ( <>
); }; window.SelectionPanel = SelectionPanel;