import { useState, useRef, useCallback, useEffect } from 'react' import { useNavigate } from 'react-router-dom' import OrderDrawer from './OrderDrawer' import useWaiterFavoritesStore from '../store/waiterFavoritesStore' import { assetUrl } from '../config/server' import { money } from '../i18n' import { useTranslation } from '@xenia/i18n' import { Allergens, useMenuText } from '@xenia/access' const FAV_CAT_ID = '__favorites__' const SVC_CAT_ID = '__service__' function CategoriesIcon({ width = 20, height = 20 }) { return ( ) } function hexToRgba(hex, alpha) { if (!hex) return null const h = hex.replace('#', '') const r = parseInt(h.substring(0, 2), 16) const g = parseInt(h.substring(2, 4), 16) const b = parseInt(h.substring(4, 6), 16) return `rgba(${r},${g},${b},${alpha})` } // A preference set blocks QuickAdd if it has NO default choice set function productAllowsQuickAdd(product) { if (!product.quick_add_enabled) return false const sets = product.preference_sets || [] for (const ps of sets) { if (ps.default_choice_id == null) return false } return true } // Decimal unit types (add 1.0 instead of 1) const DECIMAL_UNITS = new Set(['kg', 'liter', 'gram', 'ml']) function buildQuickAddItem(product) { const qty = DECIMAL_UNITS.has(product.unit_type) ? 1.0 : 1 // Auto-resolve preference sets via their default choice const selectedOptions = [] for (const ps of (product.preference_sets || [])) { const defaultChoice = ps.choices?.find(c => c.id === ps.default_choice_id) if (defaultChoice) { selectedOptions.push({ id: defaultChoice.id, name: defaultChoice.name, price_delta: defaultChoice.extra_cost ?? 0 }) } } return { product_id: product.id, quantity: qty, unit_type: product.unit_type || 'piece', unit_price: product.base_price, notes: '', selected_options: selectedOptions, removed_ingredients: [], } } // ── Product Detail Modal (long-press) ───────────────────────────────────────── function ProductDetailModal({ product, onClose }) { // Dismiss on Escape useEffect(() => { function onKey(e) { if (e.key === 'Escape') onClose() } window.addEventListener('keydown', onKey) return () => window.removeEventListener('keydown', onKey) }, [onClose]) const mt = useMenuText() // 6R.L: names in the waiter's language (display only) const initials = mt(product).trim().split(/\s+/).slice(0, 2).map(w => w[0]).join('').toUpperCase() return ( <>
{t('picker.noService')}
) : products.map(p => ({t('picker.noFavorites')}
{t('picker.noProducts')}
)} > ) : ( // Has sub-categories: accordion view