import { useState, useEffect, useRef } from 'react'
import { useCan, useMenuText } from '@xenia/access'
import useWaiterFavoritesStore from '../store/waiterFavoritesStore'
import { assetUrl } from '../config/server'
import { money } from '../i18n'
import { parseNumber, useTranslation } from '@xenia/i18n'
import PriceReason from './PriceReason'
import { priceReasonText } from '../logic/priceRules'
import { usePriceRules } from '../hooks/usePriceRules'
// ── Helpers ──────────────────────────────────────────────────────────────────
function buildInitialState(product) {
const preferenceSets = product.preference_sets || []
const prefs = {}
const subChoices = {}
const sharedSubs = {}
preferenceSets.forEach(ps => {
const def = ps.default_choice_id != null
? ps.choices.find(c => c.id === ps.default_choice_id) ?? null
: null
prefs[ps.id] = def
if (def) {
if (def.sub_choices?.length > 0) {
subChoices[def.id] = def.sub_choices.find(s => s.is_default) ?? def.sub_choices[0]
}
if (ps.shared_subset?.choices?.length > 0 && !def.disables_subset) {
sharedSubs[ps.id] = ps.shared_subset.choices.find(s => s.is_default) ?? ps.shared_subset.choices[0]
}
}
})
return { prefs, subChoices, sharedSubs }
}
// Build sorted favorites list across all item types.
// waiterOverride shape: { quick: id[], ingredients: id[], options: id[], prefs: id[] }
// If provided, it fully replaces manager's is_favorite flags.
// Order within each section follows the waiter's id array order.
function buildFavorites(product, waiterOverride) {
const items = []
if (waiterOverride) {
const qi = waiterOverride.quick || []
const ii = waiterOverride.ingredients || []
const oi = waiterOverride.options || []
const pi = waiterOverride.prefs || []
qi.forEach((id, idx) => {
const q = (product.quick_options || []).find(x => x.id === id)
if (q) items.push({ type: 'quick', item: q, sortOrder: idx })
})
ii.forEach((id, idx) => {
const ing = (product.ingredients || []).find(x => x.id === id)
if (ing) items.push({ type: 'ingredient', item: ing, sortOrder: 1000 + idx })
})
oi.forEach((id, idx) => {
const opt = (product.options || []).find(x => x.id === id)
if (opt) items.push({ type: 'option', item: opt, sortOrder: 2000 + idx })
})
pi.forEach((id, idx) => {
const ps = (product.preference_sets || []).find(x => x.id === id)
if (ps) items.push({ type: 'pref', item: ps, sortOrder: 3000 + idx })
})
} else {
// Fall back to manager's is_favorite flags
;(product.quick_options || []).forEach(q => {
if (q.is_favorite) items.push({ type: 'quick', item: q, sortOrder: q.favorite_sort_order ?? 0 })
})
;(product.ingredients || []).forEach(ing => {
if (ing.is_favorite) items.push({ type: 'ingredient', item: ing, sortOrder: ing.favorite_sort_order ?? 0 })
})
;(product.options || []).forEach(opt => {
if (opt.is_favorite) items.push({ type: 'option', item: opt, sortOrder: opt.favorite_sort_order ?? 0 })
})
;(product.preference_sets || []).forEach(ps => {
if (ps.is_favorite) items.push({ type: 'pref', item: ps, sortOrder: ps.favorite_sort_order ?? 0 })
})
}
return items.sort((a, b) => a.sortOrder - b.sortOrder)
}
// ── Primitives ────────────────────────────────────────────────────────────────
function Stepper({ value, onChange, min = 0, max = 99 }) {
return (
e.stopPropagation()}>
onChange(Math.max(min, value - 1))} disabled={value <= min}
style={{ width: 40, height: 40, border: 'none', background: 'transparent', fontSize: 18, fontWeight: 500, cursor: value <= min ? 'default' : 'pointer', color: value <= min ? 'var(--muted)' : 'var(--text)' }}>−
{value}
onChange(Math.min(max, value + 1))} disabled={value >= max}
style={{ width: 40, height: 40, border: 'none', background: 'transparent', fontSize: 18, fontWeight: 500, cursor: value >= max ? 'default' : 'pointer', color: value >= max ? 'var(--muted)' : 'var(--text)' }}>+
)
}
function CheckCircle({ selected }) {
return (
)
}
function RadioDot({ selected }) {
return (
)
}
function Row({ selected, onClick, children, right, left, style = {} }) {
return (
{left &&
{left}
}
{children}
{right &&
{right}
}
)
}
// ── Shared: single quick option row ──────────────────────────────────────────
function QuickOptionRow({ opt, quickState, setQuickState, compact }) {
const { t } = useTranslation('waiter')
const mt = useMenuText() // 6R.L: names in the waiter's language; state and lines keep ids / stored names
const qty = quickState[opt.id] || 0
const selected = qty > 0
const toggleSingle = () => setQuickState(s => ({ ...s, [opt.id]: selected ? 0 : 1 }))
return (
}
right={opt.allow_multiple ? (
e.stopPropagation()}>
{selected
?
setQuickState(s => ({ ...s, [opt.id]: v }))} />
: { e.stopPropagation(); setQuickState(s => ({ ...s, [opt.id]: 1 })) }}
style={{ width: 34, height: 34, borderRadius: '50%', background: 'var(--bg3)', border: '1px solid var(--border)', color: 'var(--text)', display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer' }}>
}
) : null}
>
{mt(opt)}
{opt.price > 0 && +{money(opt.price)}{opt.allow_multiple ? ` ${t('drawer.each')}` : ''}
}
)
}
// ── Shared: single extra/option row ──────────────────────────────────────────
function ExtraOptionRow({ opt, extrasState, setExtrasState, expandedExtra, setExpandedExtra, compact }) {
const { t } = useTranslation('waiter')
const mt = useMenuText() // 6R.L: names in the waiter's language; state and lines keep ids / stored names
const sel = extrasState[opt.id]
const selected = !!sel
const open = expandedExtra === opt.id
const hasSubs = opt.sub_choices?.length > 0
const isMultiSelect = opt.multi_select && hasSubs
// Build sub label for non-multi-select mode
const subLabel = (!isMultiSelect && sel)
? opt.sub_choices?.find(s => s.name === sel.subName)?.name ?? null
: null
// For multi-select: subs is { [subName]: qty }
const subs = sel?.subs ?? {}
const selectedSubCount = Object.values(subs).filter(q => q > 0).length
const toggle = () => {
if (selected) {
setExtrasState(s => { const n = { ...s }; delete n[opt.id]; return n })
if (open) setExpandedExtra(null)
} else {
if (isMultiSelect) {
setExtrasState(s => ({ ...s, [opt.id]: { qty: 1, subName: null, subs: {} } }))
setExpandedExtra(opt.id)
} else {
const firstSub = hasSubs ? opt.sub_choices[0] : null
setExtrasState(s => ({ ...s, [opt.id]: { qty: 1, subName: firstSub?.name ?? null, subs: {} } }))
if (hasSubs) setExpandedExtra(opt.id)
}
}
}
return (
|
}
right={
e.stopPropagation()}>
{opt.allow_multiple && !selected && (
{ e.stopPropagation(); toggle() }}
style={{ width: 34, height: 34, borderRadius: '50%', background: 'var(--bg3)', border: '1px solid var(--border)', color: 'var(--text)', display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer' }}>
)}
{selected && opt.allow_multiple && !isMultiSelect && (
{
if (v === 0) { setExtrasState(s => { const n = { ...s }; delete n[opt.id]; return n }); return }
setExtrasState(s => ({ ...s, [opt.id]: { ...sel, qty: v } }))
}} />
)}
{selected && hasSubs && (
{ e.stopPropagation(); setExpandedExtra(open ? null : opt.id) }}
style={{ width: 36, height: 36, borderRadius: '50%', background: 'var(--bg3)', border: '1px solid var(--border)', color: 'var(--text)', display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer' }}>
)}
}
style={compact ? { minHeight: 48 } : {}}
>
{mt(opt)}
{(opt.extra_cost ?? 0) !== 0 ? `+${money(opt.extra_cost)}` : t('drawer.included')}
{subLabel && · {subLabel} }
{isMultiSelect && selectedSubCount > 0 && (
· {t('drawer.selectedCount', { count: selectedSubCount })}
)}
{/* Single-select sub-choices (radio) */}
{selected && open && hasSubs && !isMultiSelect && (
{t('drawer.choose')}
{opt.sub_choices.map((sub, si) => {
const isSel = sel.subName === sub.name
return (
setExtrasState(s => ({ ...s, [opt.id]: { ...sel, subName: sub.name } }))}
left={ }
style={sub.is_compact ? { minHeight: 44 } : {}}>
{mt(sub)}
{(sub.extra_cost ?? 0) !== 0 &&
+{money(sub.extra_cost)}
}
)
})}
)}
{/* Multi-select sub-choices (checkboxes, optional qty stepper per sub) */}
{selected && open && hasSubs && isMultiSelect && (
{t('drawer.chooseMany')}
{opt.sub_choices.map((sub, si) => {
const subQty = subs[sub.name] || 0
const subSel = subQty > 0
const toggleSub = () => {
const newSubs = { ...subs, [sub.name]: subSel ? 0 : 1 }
setExtrasState(s => ({ ...s, [opt.id]: { ...sel, subs: newSubs } }))
}
return (
|
}
right={sub.allow_multiple && subSel ? (
e.stopPropagation()}>
{
const newSubs = { ...subs, [sub.name]: v }
setExtrasState(s => ({ ...s, [opt.id]: { ...sel, subs: newSubs } }))
}} />
) : null}
style={sub.is_compact ? { minHeight: 44 } : {}}>
{mt(sub)}
{subQty > 1 && ×{subQty} }
{(sub.extra_cost ?? 0) !== 0 &&
+{money(sub.extra_cost)}{sub.allow_multiple ? ` ${t('drawer.each')}` : ''}
}
)
})}
)}
)
}
// ── Shared: single ingredient row ─────────────────────────────────────────────
function IngredientRow({ ing, removedState, setRemovedState, compact }) {
const { t } = useTranslation('waiter')
const mt = useMenuText() // 6R.L: names in the waiter's language; state and lines keep ids / stored names
const removed = !!removedState[ing.id]
return (
setRemovedState(s => ({ ...s, [ing.id]: !s[ing.id] }))}
style={compact ? { minHeight: 48 } : {}}
right={
{removed ? t('drawer.removed') : t('drawer.remove')}
}>
{mt(ing)}
)
}
// ── Shared: single preference set ─────────────────────────────────────────────
function PrefSetBlock({ ps, prefs, setPrefs, subChoices, setSubChoices, sharedSubs, setSharedSubs }) {
const { t } = useTranslation('waiter')
const mt = useMenuText() // 6R.L: names in the waiter's language; state and lines keep ids / stored names
const selChoice = prefs[ps.id] ?? null
const complete = selChoice != null
&& !(selChoice.sub_choices?.length > 0 && subChoices[selChoice.id] == null)
&& !(ps.shared_subset?.choices?.length > 0 && !selChoice.disables_subset && sharedSubs[ps.id] == null)
const showShared = ps.shared_subset?.choices?.length > 0 && selChoice != null && !selChoice.disables_subset
function selectPref(choice) {
setPrefs(p => ({ ...p, [ps.id]: choice }))
if (choice?.sub_choices?.length > 0) {
setSubChoices(s => ({ ...s, [choice.id]: s[choice.id] ?? (choice.sub_choices.find(x => x.is_default) ?? choice.sub_choices[0]) }))
}
if (ps.shared_subset?.choices?.length > 0 && !choice?.disables_subset) {
setSharedSubs(s => s[ps.id] != null ? s : { ...s, [ps.id]: ps.shared_subset.choices.find(x => x.is_default) ?? ps.shared_subset.choices[0] })
}
}
return (
{mt(ps)}
{!complete &&
{t('drawer.required')}
}
{ps.choices.map(ch => {
const isSel = selChoice?.id === ch.id
const hasSubs = ch.sub_choices?.length > 0
const subMissing = isSel && hasSubs && subChoices[ch.id] == null
return (
selectPref(ch)} left={ }
style={ch.is_compact ? { minHeight: 48 } : {}}
right={(ch.extra_cost ?? 0) !== 0 ? {ch.extra_cost > 0 ? '+' : ''}{money(ch.extra_cost)}
: null}>
{mt(ch)}
{isSel && hasSubs && (
{subMissing &&
{t('drawer.choiceRequired')}
}
{ch.sub_choices.map((sub, si) => {
const subSel = subChoices[ch.id]?.name === sub.name
return (
setSubChoices(s => ({ ...s, [ch.id]: sub }))} left={ }
style={sub.is_compact ? { minHeight: 44 } : {}}
right={(sub.extra_cost ?? 0) !== 0 ? +{money(sub.extra_cost)}
: null}>
{mt(sub)}
)
})}
)}
)
})}
{showShared && (
{mt(ps.shared_subset)}
{ps.shared_subset.choices.map((sub, si) => {
const subSel = sharedSubs[ps.id]?.name === sub.name
return (
setSharedSubs(s => ({ ...s, [ps.id]: sub }))} left={ }
style={sub.is_compact ? { minHeight: 44 } : {}}
right={(sub.extra_cost ?? 0) !== 0 ? +{money(sub.extra_cost)}
: null}>
{mt(sub)}
)
})}
)}
)
}
// ── Tab: Favorites ────────────────────────────────────────────────────────────
function FavoritesTab({ product, waiterOverride, quickState, setQuickState, extrasState, setExtrasState, expandedExtra, setExpandedExtra, removedState, setRemovedState, prefs, setPrefs, subChoices, setSubChoices, sharedSubs, setSharedSubs }) {
const { t } = useTranslation('waiter')
const favorites = buildFavorites(product, waiterOverride)
if (favorites.length === 0) return (
{t('drawer.empty.favorites')}
)
return (
{favorites.map((fav, _fi) => {
if (fav.type === 'quick') {
return
}
if (fav.type === 'ingredient') {
return
}
if (fav.type === 'option') {
return
}
if (fav.type === 'pref') {
return (
)
}
return null
})}
)
}
// ── Tab: Quick Options ────────────────────────────────────────────────────────
function QuickTab({ product, quickState, setQuickState }) {
const { t } = useTranslation('waiter')
const quickOptions = product.quick_options || []
if (quickOptions.length === 0) return (
{t('drawer.empty.quick')}
)
return (
{quickOptions.map(opt => (
))}
)
}
// ── Shared: PWA group sticky header ──────────────────────────────────────────
// Static group colours — cycle by index passed from parent
const GROUP_COLORS = [
{ bg: 'var(--x-info-soft)', border: 'var(--x-info-ink)', text: 'var(--x-info)' }, // indigo
{ bg: 'var(--x-special-soft)', border: 'var(--x-special-ink)', text: 'var(--x-special)' }, // pink
{ bg: 'var(--x-success-soft)', border: 'var(--x-success)', text: 'var(--x-success-soft)' }, // emerald
{ bg: 'var(--x-warning-soft)', border: 'var(--x-warning)', text: 'var(--x-warning)' }, // amber
{ bg: 'var(--x-info-soft)', border: 'var(--x-info-ink)', text: 'var(--x-info)' }, // sky
{ bg: 'var(--x-special-soft)', border: 'var(--x-special-ink)', text: 'var(--x-special)' }, // purple
]
function PWAGroupHeader({ name, collapsed, onToggle, colorIdx = 0 }) {
const c = GROUP_COLORS[colorIdx % GROUP_COLORS.length]
return (
{name}
▾
)
}
// Partition items into { ungrouped, groups: [{group, items}] } preserving order
function partitionByGroup(items, modifierGroups) {
if (!modifierGroups || modifierGroups.length === 0) return { ungrouped: items, groups: [] }
const groupMap = {}
modifierGroups.forEach(g => { groupMap[g.id] = { group: g, items: [] } })
const ungrouped = []
items.forEach(item => {
if (item.group_id != null && groupMap[item.group_id]) {
groupMap[item.group_id].items.push(item)
} else {
ungrouped.push(item)
}
})
// Preserve group order from modifierGroups
const groups = modifierGroups.map(g => groupMap[g.id]).filter(g => g.items.length > 0)
return { ungrouped, groups }
}
// ── Tab: Extras ───────────────────────────────────────────────────────────────
function ExtrasTab({ product, extrasState, setExtrasState, expandedExtra, setExpandedExtra }) {
const { t } = useTranslation('waiter')
const mt = useMenuText() // 6R.L: names in the waiter's language; state and lines keep ids / stored names
const extraGroups = (product.modifier_groups || []).filter(g => g.modifier_type === 'option')
const [collapsedGroups, setCollapsedGroups] = useState(() => Object.fromEntries(extraGroups.map(g => [g.id, true])))
const options = product.options || []
if (options.length === 0) return (
{t('drawer.empty.extras')}
)
function toggleGroup(id) { setCollapsedGroups(s => ({ ...s, [id]: !s[id] })) }
const { ungrouped, groups } = partitionByGroup(options, extraGroups)
function renderOption(opt) {
return (
)
}
return (
{ungrouped.length > 0 && (
0 ? 12 : 0 }}>
{ungrouped.map(renderOption)}
)}
{groups.map(({ group, items }, gi) => {
const isCollapsed = collapsedGroups[group.id] ?? true
return (
toggleGroup(group.id)} colorIdx={gi} />
{!isCollapsed && (
{items.map(renderOption)}
)}
)
})}
)
}
// ── Tab: Ingredients ─────────────────────────────────────────────────
function IngredientsTab({ product, removedState, setRemovedState }) {
const { t } = useTranslation('waiter')
const mt = useMenuText() // 6R.L: names in the waiter's language; state and lines keep ids / stored names
const ingGroups = (product.modifier_groups || []).filter(g => g.modifier_type === 'ingredient')
const [collapsedGroups, setCollapsedGroups] = useState(() => Object.fromEntries(ingGroups.map(g => [g.id, true])))
const ingredients = product.ingredients || []
if (ingredients.length === 0) return (
{t('drawer.empty.ingredients')}
)
function toggleGroup(id) { setCollapsedGroups(s => ({ ...s, [id]: !s[id] })) }
const { ungrouped, groups } = partitionByGroup(ingredients, ingGroups)
function renderIng(ing) {
return (
)
}
return (
{ungrouped.length > 0 && (
0 ? 12 : 0 }}>
{ungrouped.map(renderIng)}
)}
{groups.map(({ group, items }, gi) => {
const isCollapsed = collapsedGroups[group.id] ?? true
return (
toggleGroup(group.id)} colorIdx={gi} />
{!isCollapsed && (
{items.map(renderIng)}
)}
)
})}
)
}
// ── Tab: Preferences ─────────────────────────────────────────────────────────
function PrefsTab({ product, prefs, setPrefs, subChoices, setSubChoices, sharedSubs, setSharedSubs }) {
const { t } = useTranslation('waiter')
const mt = useMenuText() // 6R.L: names in the waiter's language; state and lines keep ids / stored names
const prefGroups = (product.modifier_groups || []).filter(g => g.modifier_type === 'preference')
const [collapsedGroups, setCollapsedGroups] = useState(() => Object.fromEntries(prefGroups.map(g => [g.id, true])))
const preferenceSets = product.preference_sets || []
if (preferenceSets.length === 0) return (
{t('drawer.empty.prefs')}
)
function toggleGroup(id) { setCollapsedGroups(s => ({ ...s, [id]: !s[id] })) }
const { ungrouped, groups } = partitionByGroup(preferenceSets, prefGroups)
function renderPrefSet(ps) {
return (
)
}
return (
{ungrouped.length > 0 && (
0 ? 16 : 0 }}>
{ungrouped.map(renderPrefSet)}
)}
{groups.map(({ group, items }, gi) => {
const isCollapsed = collapsedGroups[group.id] ?? true
return (
toggleGroup(group.id)} colorIdx={gi} />
{!isCollapsed && (
{items.map(renderPrefSet)}
)}
)
})}
)
}
// ── Tab: Quantity (for KG / Liter / Gram / mL units) ─────────────────────────
const DECIMAL_UNIT_CONFIG = {
kg: { step: 0.05, min: 0.05, presets: [0.10, 0.20, 0.25, 0.50, 0.70, 1.00, 1.50, 2.00, 2.50, 3.00, 4.00, 5.00], offsets: [0.1, 0.2, 0.5, 1.0], label: 'kg' },
liter: { step: 0.05, min: 0.05, presets: [0.10, 0.20, 0.25, 0.50, 0.70, 1.00, 1.50, 2.00, 2.50, 3.00, 4.00, 5.00], offsets: [0.1, 0.2, 0.5, 1.0], label: 'L' },
gram: { step: 10, min: 10, presets: [50, 100, 150, 200, 250, 300, 400, 500], offsets: [10, 50, 100, 200], label: 'g' },
ml: { step: 5, min: 5, presets: [25, 50, 100, 150, 200, 250, 300, 500], offsets: [25, 50, 100, 200], label: 'mL' },
}
function fmtDecimalQty(qty, cfg) {
if (!cfg) return String(qty)
if (cfg.label === 'kg' || cfg.label === 'L') {
const n = Number(qty)
return n % 1 === 0 ? n.toFixed(1) : (Math.round(n * 100) / 100).toFixed(2).replace(/0$/, '')
}
return String(qty)
}
function QuantityTab({ unitCfg, qty, setQty }) {
const { t } = useTranslation('waiter')
const [editingQty, setEditingQty] = useState(false)
const [qtyInput, setQtyInput] = useState('')
const inputRef = useRef(null)
function clamp(v) { return Math.max(unitCfg.min, Math.round(v * 1000) / 1000) }
return (
{/* Main − / value / + row */}
setQty(q => clamp(q - unitCfg.step))}
style={{ width: 52, height: 52, border: 'none', background: 'transparent', fontSize: 22, fontWeight: 500, cursor: 'pointer', color: 'var(--text)' }}
>−
{editingQty ? (
setQtyInput(e.target.value)}
onBlur={() => {
const v = parseNumber(qtyInput, { decimals: 3, allowNegative: false })
if (v != null) setQty(clamp(v))
setEditingQty(false)
}}
onKeyDown={e => { if (e.key === 'Enter') e.target.blur() }}
autoFocus
style={{
width: 80, height: 52, border: 'none', background: 'transparent',
textAlign: 'center', fontSize: 17, fontWeight: 700, color: 'var(--text)',
fontVariantNumeric: 'tabular-nums', outline: 'none', fontFamily: 'inherit',
}}
/>
) : (
{ setQtyInput(String(qty)); setEditingQty(true) }}
style={{ minWidth: 80, textAlign: 'center', fontSize: 17, fontWeight: 700, color: 'var(--text)', fontVariantNumeric: 'tabular-nums', cursor: 'text', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 4 }}
>
{fmtDecimalQty(qty, unitCfg)}
{unitCfg.label}
)}
setQty(q => clamp(q + unitCfg.step))}
style={{ width: 52, height: 52, border: 'none', background: 'transparent', fontSize: 22, fontWeight: 500, cursor: 'pointer', color: 'var(--text)' }}
>+
{/* Quick presets — 3 rows of 4 */}
{t('drawer.qty.quickPick')}
{unitCfg.presets.map(v => (
setQty(v)}
style={{
padding: '10px 4px', borderRadius: 12, border: 'none',
background: qty === v ? 'var(--accent)' : 'var(--bg3)',
color: qty === v ? 'var(--accent-fg)' : 'var(--text)',
fontSize: 13, fontWeight: 700, cursor: 'pointer',
textAlign: 'center',
}}
>
{fmtDecimalQty(v, unitCfg)}{unitCfg.label}
))}
{/* Quick ± offset buttons — 2×2 grid */}
{t('drawer.qty.quickAdd')}
{unitCfg.offsets.map(off => (
setQty(q => clamp(q + off))}
style={{
padding: '10px 4px', borderRadius: 12, border: 'none',
background: 'rgb(var(--x-success-rgb) / 0.12)', color: 'var(--x-success)',
fontSize: 13, fontWeight: 700, cursor: 'pointer', textAlign: 'center',
}}
>+{fmtDecimalQty(off, unitCfg)}{unitCfg.label}
))}
{unitCfg.offsets.map(off => (
setQty(q => clamp(q - off))}
style={{
padding: '10px 4px', borderRadius: 12, border: 'none',
background: 'rgb(var(--x-danger-rgb) / 0.12)', color: 'var(--x-danger-ink)',
fontSize: 13, fontWeight: 700, cursor: 'pointer', textAlign: 'center',
}}
>−{fmtDecimalQty(off, unitCfg)}{unitCfg.label}
))}
)
}
// ── Tab: Price Adjustment ─────────────────────────────────────────────────────
const PRICE_DELTAS = [-5, -3, -2, -1, -0.5, -0.2, +0.2, +0.5, +1, +2, +3, +5]
function PriceAdjustTab({ basePrice, priceAdj, setPriceAdj, rules, reason, setReason, reasonMissing }) {
const { t } = useTranslation('waiter')
const [editing, setEditing] = useState(false)
const [rawInput, setRawInput] = useState('')
const inputRef = useRef(null)
const effectivePrice = basePrice + priceAdj
function applyDelta(d) {
setPriceAdj(a => {
const next = Math.round((a + d) * 100) / 100
const min = -(basePrice - 0.01)
return Math.max(min, next)
})
}
function commitInput() {
const v = parseNumber(rawInput, { decimals: 2, allowNegative: false })
if (v != null && v >= 0.01) {
setPriceAdj(Math.round((v - basePrice) * 100) / 100)
}
setEditing(false)
}
useEffect(() => {
if (editing && inputRef.current) inputRef.current.focus()
}, [editing])
return (
{t('drawer.price.intro')}
{/* Price display / input */}
applyDelta(-0.1)} style={{ width: 44, height: 44, borderRadius: '50%', border: '1.5px solid var(--border)', background: 'var(--bg3)', fontSize: 20, fontWeight: 700, color: 'var(--text)', cursor: 'pointer' }}>−
{editing ? (
setRawInput(e.target.value)}
onBlur={commitInput}
onKeyDown={e => { if (e.key === 'Enter') e.target.blur() }}
style={{ width: 110, height: 52, border: '2px solid var(--x-warning)', borderRadius: 14, background: 'var(--bg2)', textAlign: 'center', fontSize: 22, fontWeight: 800, color: 'var(--x-warning)', outline: 'none', fontFamily: 'inherit' }}
/>
) : (
{ setRawInput(effectivePrice.toFixed(2)); setEditing(true) }} style={{
minWidth: 110, height: 52, borderRadius: 14,
border: `2px solid ${priceAdj !== 0 ? 'var(--x-warning)' : 'var(--border)'}`,
background: priceAdj !== 0 ? 'rgb(var(--x-warning-rgb) / 0.12)' : 'var(--bg2)',
color: priceAdj !== 0 ? 'var(--x-warning)' : 'var(--text)',
fontSize: 22, fontWeight: 800, cursor: 'pointer', fontFamily: 'inherit',
}}>
{money(effectivePrice)}
)}
applyDelta(+0.1)} style={{ width: 44, height: 44, borderRadius: '50%', border: '1.5px solid var(--border)', background: 'var(--bg3)', fontSize: 20, fontWeight: 700, color: 'var(--text)', cursor: 'pointer' }}>+
{priceAdj !== 0 && (
{t('drawer.price.base', { price: money(basePrice) })}
0 ? 'var(--x-success)' : 'var(--x-danger)' }}>
{priceAdj > 0 ? '+' : ''}{money(priceAdj)}
setPriceAdj(0)} style={{ padding: '3px 10px', borderRadius: 8, border: '1px solid var(--border)', background: 'var(--bg3)', color: 'var(--muted)', fontSize: 12, cursor: 'pointer' }}>{t('settings.reset.title')}
)}
{/* Quick delta grid — 4 rows × 3 */}
{PRICE_DELTAS.map(d => (
applyDelta(d)}
style={{
padding: '11px 4px', borderRadius: 12, border: 'none',
background: d < 0 ? 'rgb(var(--x-danger-rgb) / 0.12)' : 'rgb(var(--x-success-rgb) / 0.12)',
color: d < 0 ? 'var(--x-danger-ink)' : 'var(--x-success)',
fontSize: 14, fontWeight: 700, cursor: 'pointer',
}}
>
{d > 0 ? '+' : ''}{d.toFixed(2 - (Number.isInteger(d) ? 2 : 0))} €
))}
{/* 6F.3: the venue asks why a price changes */}
{rules?.reasonRequired && priceAdj !== 0 &&
}
)
}
// ── Tab: Notes ────────────────────────────────────────────────────────────────
function NotesTab({ note, setNote, quickNotes }) {
const { t } = useTranslation('waiter')
quickNotes = quickNotes ?? FALLBACK_QUICK_NOTES.map(k => t(k))
return (
)
}
// ── Tab: Summary ──────────────────────────────────────────────────────────────
/** One group of the summary (prefs, quick options, extras, removed) with its "change" link. */
function Section({ title, tab, lines, onJumpTab }) {
const { t } = useTranslation('waiter')
if (lines.length === 0) return null
return (
{title}
onJumpTab(tab)} style={{ background: 'none', border: 'none', fontSize: 12, fontWeight: 700, color: 'var(--x-warning)', cursor: 'pointer', textTransform: 'uppercase', letterSpacing: 0.6 }}>{t('common.change')}
{lines.map((l, i) => (
{l.group === 'prefs' ? (
<>
{l.label}
{l.value}
>
) : l.group === 'removed' ? (
{t('drawer.without', { name: l.label })}
) : l.group === 'extras' ? (
{l.label}
{l.subName && · {l.subName} }
{l.qty > 1 && ×{l.qty} }
) : (
{l.qty > 1 && {l.qty}× }
{l.label}
)}
{l.price !== 0 &&
{l.price > 0 ? '+' : ''}{money(l.price)}
}
))}
)
}
function SummaryTab({ _product, summaryLines, note, onJumpTab }) {
const { t } = useTranslation('waiter')
const isEmpty = summaryLines.length === 0 && !note
const byGroup = { quick: [], extras: [], removed: [], prefs: [] }
summaryLines.forEach(l => byGroup[l.group]?.push(l))
return (
{isEmpty ? (
{t('drawer.summary.empty')}
) : (
<>
{note && (
{t('drawer.tabs.note')}
onJumpTab('notes')} style={{ background: 'none', border: 'none', fontSize: 12, fontWeight: 700, color: 'var(--x-warning)', cursor: 'pointer', textTransform: 'uppercase', letterSpacing: 0.6 }}>{t('common.change')}
{note}
)}
>
)}
)
}
// ── Main OrderDrawer ──────────────────────────────────────────────────────────
function CoursesTab({ courses, courseId, setCourseId }) {
return (
setCourseId(null)}
style={{
padding: '10px 14px', borderRadius: 10, textAlign: 'left',
background: courseId === null ? 'var(--accent)' : 'var(--card)',
color: courseId === null ? 'var(--x-ink)' : 'var(--text)',
border: `2px solid ${courseId === null ? 'var(--accent)' : 'var(--line)'}`,
fontWeight: 600, fontSize: 14, cursor: 'pointer', fontFamily: 'inherit',
}}
>
No course (fire immediately)
{courses.map(c => (
setCourseId(courseId === c.id ? null : c.id)}
style={{
padding: '10px 14px', borderRadius: 10, textAlign: 'left',
background: courseId === c.id ? c.color : 'var(--card)',
color: courseId === c.id ? 'var(--x-ink)' : 'var(--text)',
border: `2px solid ${courseId === c.id ? c.color : 'var(--line)'}`,
fontWeight: 600, fontSize: 14, cursor: 'pointer', fontFamily: 'inherit',
display: 'flex', alignItems: 'center', gap: 10,
}}
>
{c.name}
))}
)
}
// the venue's own quick notes (Settings) win; these are the defaults, in the waiter's language
const FALLBACK_QUICK_NOTES = ['drawer.notes.noSalt', 'drawer.notes.quick', 'drawer.notes.allergy', 'drawer.notes.smallPieces', 'drawer.notes.napkins']
export default function OrderDrawer({ product, isOpen, onClose, onAdd, initialState, courses, quickNotes }) {
const { t } = useTranslation('waiter')
const mt = useMenuText() // 6R.L: names in the waiter's language; state and lines keep ids / stored names
const itemFavorites = useWaiterFavoritesStore(s => s.itemFavorites)
// A price set before sending needs the key itself (plan 4.3); the manager-approval path for
// it comes with server-priced orders (4.4). After sending, the item's actions offer it.
// 6F.3: and the venue allows prices typed before sending (orders.price_change)
const priceRulesNow = usePriceRules()
const priceAdjAllowed = useCan('ordering.prices.modify') && priceRulesNow.inCart
const preferenceSets = product?.preference_sets || []
const quickOptions = product?.quick_options || []
const options = product?.options || []
const ingredients = product?.ingredients || []
const waiterOverride = product ? (itemFavorites[product.id] ?? null) : null
const favorites = product ? buildFavorites(product, waiterOverride) : []
const unitCfg = product ? (DECIMAL_UNIT_CONFIG[product.unit_type] ?? null) : null
const isDecimal = !!unitCfg
const hasTabs = {
favorites: favorites.length > 0,
quick: quickOptions.length > 0,
extras: options.length > 0,
ingredients: ingredients.length > 0,
prefs: preferenceSets.length > 0,
quantity: isDecimal,
}
const coursePreselected = initialState?.courseId != null
// A pref is "mandatory unset" when it has no default and isn't already in favorites
const prefsMandatoryUnset = hasTabs.prefs && preferenceSets.some(ps => ps.default_choice_id == null)
const mandatoryPrefInFavorites = prefsMandatoryUnset && preferenceSets
.filter(ps => ps.default_choice_id == null)
.every(ps => favorites.some(f => f.type === 'pref' && f.item.id === ps.id))
const firstTab = (() => {
// 1. Mandatory pref exists and IS covered by favorites → show favorites
if (prefsMandatoryUnset && mandatoryPrefInFavorites && hasTabs.favorites) return 'favorites'
// 2. Mandatory pref exists and NOT in favorites → show prefs
if (prefsMandatoryUnset && !mandatoryPrefInFavorites) return 'prefs'
// 3. No mandatory pref → favorites if they exist
if (hasTabs.favorites) return 'favorites'
// 4. No favorites, courses enabled and not preselected → courses
if (courses?.length > 0 && !coursePreselected) return 'courses'
// 5. Fallback
return 'notes'
})()
const [activeTab, setActiveTab] = useState(firstTab)
const tabsScrollRef = useRef(null)
const tabButtonRefs = useRef({})
// Scroll active tab to center of the tabs bar whenever it changes or the drawer opens
useEffect(() => {
if (!isOpen) return
const id = requestAnimationFrame(() => {
const bar = tabsScrollRef.current
const btn = tabButtonRefs.current[activeTab]
if (!bar || !btn) return
bar.scrollLeft = btn.offsetLeft - bar.clientWidth / 2 + btn.offsetWidth / 2
})
return () => cancelAnimationFrame(id)
}, [activeTab, isOpen])
const [qty, setQty] = useState(isDecimal ? (unitCfg?.presets[0] ?? 0.1) : 1)
const [quickState, setQuickState] = useState({})
const [extrasState, setExtrasState] = useState({})
const [expandedExtra, setExpandedExtra] = useState(null)
const [removedState, setRemovedState] = useState({})
const [prefs, setPrefs] = useState({})
const [subChoices, setSubChoices] = useState({})
const [sharedSubs, setSharedSubs] = useState({})
const [note, setNote] = useState('')
const [priceAdj, setPriceAdj] = useState(0)
const [priceReason, setPriceReason] = useState({ choice: '', other: '' }) // 6F.3
const [addAttempted, setAddAttempted] = useState(false)
const [courseId, setCourseId] = useState(initialState?.courseId ?? null)
// Reset/init when drawer opens or product changes
useEffect(() => {
if (!isOpen || !product) return
const base = buildInitialState(product)
if (initialState) {
setQty(initialState.qty ?? (isDecimal ? (unitCfg?.presets[0] ?? 0.1) : 1))
setQuickState(initialState.quickState ?? {})
setExtrasState(initialState.extrasState ?? {})
setRemovedState(initialState.removedState ?? {})
setPrefs(initialState.prefs ?? base.prefs)
setSubChoices(initialState.subChoices ?? base.subChoices)
setSharedSubs(initialState.sharedSubs ?? base.sharedSubs)
setNote(initialState.note ?? '')
setPriceAdj(initialState.priceAdj ?? 0)
setPriceReason(initialState.priceReason ?? { choice: '', other: '' })
setCourseId(initialState.courseId ?? null)
} else {
setQty(isDecimal ? (unitCfg?.presets[0] ?? 0.1) : 1)
setQuickState({})
setExtrasState({})
setRemovedState({})
setPrefs(base.prefs)
setSubChoices(base.subChoices)
setSharedSubs(base.sharedSubs)
setNote('')
setPriceAdj(0)
setPriceReason({ choice: '', other: '' })
setCourseId(null)
}
setExpandedExtra(null)
setAddAttempted(false)
setActiveTab(initialState?.activeTab ?? firstTab)
}, [isOpen, product?.id])
// Derived: summary lines + price
const { summaryLines, totalPrice } = (() => {
if (!product) return { summaryLines: [], totalPrice: 0 }
let price = product.base_price
const lines = []
preferenceSets.forEach(ps => {
const choice = prefs[ps.id]
if (!choice) return
const inlineSub = choice.sub_choices?.length > 0 ? (subChoices[choice.id] ?? null) : null
const sharedSub = (ps.shared_subset?.choices?.length > 0 && !choice.disables_subset) ? (sharedSubs[ps.id] ?? null) : null
const delta = (choice.extra_cost ?? 0) + (inlineSub?.extra_cost ?? 0) + (sharedSub?.extra_cost ?? 0)
// Skip if this is entirely the default selection
const defaultChoice = ps.default_choice_id != null ? ps.choices.find(c => c.id === ps.default_choice_id) : null
const isDefaultChoice = defaultChoice && choice.id === defaultChoice.id
const defaultInlineSub = isDefaultChoice && defaultChoice.sub_choices?.length > 0
? (defaultChoice.sub_choices.find(s => s.is_default) ?? defaultChoice.sub_choices[0])
: null
const defaultSharedSub = isDefaultChoice && ps.shared_subset?.choices?.length > 0 && !choice.disables_subset
? (ps.shared_subset.choices.find(s => s.is_default) ?? ps.shared_subset.choices[0])
: null
const isFullyDefault = isDefaultChoice
&& (!inlineSub || inlineSub.name === defaultInlineSub?.name)
&& (!sharedSub || sharedSub.name === defaultSharedSub?.name)
if (isFullyDefault) { price += delta; return }
const value = `${mt(choice)}${inlineSub ? ` · ${mt(inlineSub)}` : ''}${sharedSub ? ` · ${mt(sharedSub)}` : ''}`
lines.push({ group: 'prefs', label: mt(ps), value, qty: 1, price: delta, detail: null })
price += delta
})
quickOptions.forEach(opt => {
const q = quickState[opt.id] || 0
if (q === 0) return
const linePrice = opt.price * q
lines.push({ group: 'quick', label: mt(opt), qty: q, price: linePrice, detail: null })
price += linePrice
})
options.forEach(opt => {
const sel = extrasState[opt.id]
if (!sel) return
if (opt.multi_select && opt.sub_choices?.length > 0) {
// Each selected sub-choice is its own line in the summary
const subs = sel.subs ?? {}
Object.entries(subs).forEach(([subName, subQty]) => {
if (!subQty || subQty < 1) return
const sub = opt.sub_choices.find(s => s.name === subName)
const linePrice = ((opt.extra_cost ?? 0) + (sub?.extra_cost ?? 0)) * subQty
lines.push({ group: 'extras', label: mt(opt), qty: subQty, price: linePrice, subName: sub ? mt(sub) : subName, detail: null })
price += linePrice
})
} else {
const sub = opt.sub_choices?.find(s => s.name === sel.subName)
const linePrice = ((opt.extra_cost ?? 0) + (sub?.extra_cost ?? 0)) * sel.qty
lines.push({ group: 'extras', label: mt(opt), qty: sel.qty, price: linePrice, subName: sub ? mt(sub) : null, detail: null })
price += linePrice
}
})
ingredients.forEach(ing => {
if (removedState[ing.id]) lines.push({ group: 'removed', label: mt(ing), qty: 1, price: 0, detail: null })
})
return { summaryLines: lines, totalPrice: (price + priceAdj) * qty }
})()
// Validation
function isPrefComplete(ps) {
const choice = prefs[ps.id]
if (!choice) return false
if (choice.sub_choices?.length > 0 && subChoices[choice.id] == null) return false
if (ps.shared_subset?.choices?.length > 0 && !choice.disables_subset && sharedSubs[ps.id] == null) return false
return true
}
const allPrefsOk = preferenceSets.every(isPrefComplete)
const extrasSubsMissing = options.some(opt => {
const sel = extrasState[opt.id]
if (!sel) return false
// multi-select: no mandatory sub required (waiter can select any combo)
if (opt.multi_select) return false
return opt.sub_choices?.length > 0 && sel.subName == null
})
const canAdd = allPrefsOk && !extrasSubsMissing
const prefsHasMandatory = hasTabs.prefs && preferenceSets.some(ps => ps.default_choice_id == null)
const prefsTabAlert = hasTabs.prefs && !allPrefsOk && (addAttempted || prefsHasMandatory)
// Also alert the favorites tab if it contains an incomplete pref
const favHasIncompletePref = hasTabs.favorites && !allPrefsOk && favorites.some(f => f.type === 'pref' && !isPrefComplete(f.item))
const favTabAlert = favHasIncompletePref && (addAttempted || prefsHasMandatory)
function handleAdd() {
const reasonTxt = priceAdj !== 0 ? priceReasonText(priceRulesNow, t, priceReason) : ''
if (priceAdj !== 0 && priceRulesNow.reasonRequired && !reasonTxt) { // 6F.3: why the price changes
setAddAttempted(true)
setActiveTab('price_adjust')
return
}
if (!canAdd) {
setAddAttempted(true)
if (!allPrefsOk) {
// Jump to favorites if the incomplete pref is there, else prefs tab
if (favHasIncompletePref) setActiveTab('favorites')
else if (hasTabs.prefs) setActiveTab('prefs')
}
return
}
const prefChoices = preferenceSets.flatMap(ps => {
const choice = prefs[ps.id]
if (!choice) return []
const inlineSub = choice.sub_choices?.length > 0 ? (subChoices[choice.id] ?? null) : null
const sharedSub = ps.shared_subset?.choices?.length > 0 && !choice.disables_subset ? (sharedSubs[ps.id] ?? null) : null
// Don't emit entries that are entirely at their defaults — nothing changed
const defaultChoice = ps.default_choice_id != null ? ps.choices.find(c => c.id === ps.default_choice_id) : null
const isDefaultChoice = defaultChoice && choice.id === defaultChoice.id
const defaultInlineSub = isDefaultChoice && defaultChoice.sub_choices?.length > 0
? (defaultChoice.sub_choices.find(s => s.is_default) ?? defaultChoice.sub_choices[0])
: null
const defaultSharedSub = isDefaultChoice && ps.shared_subset?.choices?.length > 0 && !choice.disables_subset
? (ps.shared_subset.choices.find(s => s.is_default) ?? ps.shared_subset.choices[0])
: null
const isFullyDefault = isDefaultChoice
&& (!inlineSub || inlineSub.name === defaultInlineSub?.name)
&& (!sharedSub || sharedSub.name === defaultSharedSub?.name)
if (isFullyDefault) return []
const entries = [{ id: choice.id, name: choice.name, price_delta: choice.extra_cost ?? 0, type: 'pref' }]
if (inlineSub) entries.push({ id: null, name: inlineSub.name, price_delta: inlineSub.extra_cost ?? 0, type: 'pref_sub' })
if (sharedSub) entries.push({ id: null, name: sharedSub.name, price_delta: sharedSub.extra_cost ?? 0, type: 'pref_sub' })
return entries
})
const optionEntries = options.flatMap(opt => {
const sel = extrasState[opt.id]
if (!sel) return []
if (opt.multi_select && opt.sub_choices?.length > 0) {
const subs = sel.subs ?? {}
return Object.entries(subs).flatMap(([subName, subQty]) => {
if (!subQty || subQty < 1) return []
const sub = opt.sub_choices.find(s => s.name === subName)
const entries = []
for (let i = 0; i < subQty; i++) {
entries.push({ id: opt.id, name: opt.name, price_delta: opt.extra_cost ?? 0, type: 'extra' })
if (sub) entries.push({ id: null, name: sub.name, price_delta: sub.extra_cost ?? 0, type: 'extra_sub' })
}
return entries
})
}
const sub = opt.sub_choices?.find(s => s.name === sel.subName)
const entries = []
for (let i = 0; i < sel.qty; i++) {
entries.push({ id: opt.id, name: opt.name, price_delta: opt.extra_cost ?? 0, type: 'extra' })
if (sub) entries.push({ id: null, name: sub.name, price_delta: sub.extra_cost ?? 0, type: 'extra_sub' })
}
return entries
})
const quickEntries = quickOptions.flatMap(opt => {
const q = quickState[opt.id] || 0
if (q === 0) return []
return Array.from({ length: q }, () => ({ id: null, name: opt.name, price_delta: opt.price ?? 0, type: 'quick' }))
})
const removedNames = ingredients.filter(ing => removedState[ing.id]).map(ing => ing.name)
onAdd({
product_id: product.id,
quantity: qty,
selected_options: [...prefChoices, ...quickEntries, ...optionEntries],
removed_ingredients: removedNames,
notes: note,
price_adjustment: priceAdj !== 0 ? priceAdj : undefined,
price_reason: reasonTxt || undefined,
course_id: courseId ?? undefined,
_drawerState: { qty, quickState, extrasState, removedState, prefs, subChoices, sharedSubs, note, priceAdj, priceReason, courseId },
})
onClose()
}
// Tabs definition — ordered, with SVG icons
const TAB_ICON = {
favorites: ,
quick: ,
extras: ,
ingredients: ,
prefs: ,
quantity: ,
courses: ,
notes: ,
price_adjust: ,
summary: ,
}
const tabs = [
hasTabs.favorites && { id: 'favorites', label: t('settings.tabs.favorites') },
hasTabs.quick && { id: 'quick', label: t('drawer.tabs.quickShort') },
hasTabs.extras && { id: 'extras', label: t('drawer.tabs.extras') },
hasTabs.ingredients && { id: 'ingredients', label: t('drawer.tabs.ingredients') },
hasTabs.prefs && { id: 'prefs', label: t('drawer.tabs.options') },
hasTabs.quantity && { id: 'quantity', label: t('drawer.tabs.quantity', { unit: unitCfg?.label }) },
(courses?.length > 0) && { id: 'courses', label: 'Courses' },
{ id: 'notes', label: t('drawer.tabs.note') },
priceAdjAllowed && { id: 'price_adjust', label: t('drawer.tabs.price') },
{ id: 'summary', label: t('drawer.tabs.summary') },
].filter(Boolean)
const badgeFor = id => {
if (id === 'favorites') {
// count favorited items that have been interacted with
const favQuick = favorites.filter(f => f.type === 'quick' && (quickState[f.item.id] || 0) > 0).length
const favIng = favorites.filter(f => f.type === 'ingredient' && removedState[f.item.id]).length
const favExt = favorites.filter(f => f.type === 'option' && extrasState[f.item.id]).length
const favPref = favorites.filter(f => f.type === 'pref' && isPrefComplete(f.item)).length
return favQuick + favIng + favExt + favPref
}
if (id === 'quick') return Object.values(quickState).filter(v => v > 0).length
if (id === 'extras') return Object.values(extrasState).filter(Boolean).length
if (id === 'ingredients') return Object.values(removedState).filter(Boolean).length
if (id === 'prefs') return preferenceSets.filter(isPrefComplete).length
if (id === 'courses') return courseId != null ? 1 : 0
if (id === 'notes') return note ? 1 : 0
if (id === 'price_adjust') return priceAdj !== 0 ? 1 : 0
if (id === 'summary') return summaryLines.length + (note ? 1 : 0) + (priceAdj !== 0 ? 1 : 0)
return 0
}
if (!product) return null
return (
<>
{/* Backdrop */}
{/* Sheet */}
{/* Grab handle */}
{/* Header */}
{product.image_url && (
)}
{mt(product)}
{priceAdj !== 0
? <>{money(product.base_price)} → {money(product.base_price + priceAdj)}>
: <>{money(product.base_price)}>
}
{/* Tabs bar */}
{tabs.map(tb => {
const active = activeTab === tb.id
const badge = badgeFor(tb.id)
const isAlert = (tb.id === 'prefs' && prefsTabAlert) || (tb.id === 'favorites' && favTabAlert)
const tabColor = isAlert ? 'var(--x-danger)' : active ? 'var(--x-warning)' : 'var(--muted)'
return (
{ tabButtonRefs.current[tb.id] = el }} onClick={() => setActiveTab(tb.id)} data-testid={`drawer-tab-${tb.id}`} style={{
padding: '12px 6px',
background: 'none', border: 'none',
borderBottom: `2px solid ${active ? 'var(--x-warning)' : isAlert ? 'var(--x-danger)' : 'transparent'}`,
color: tabColor,
fontSize: 13, fontWeight: (active || isAlert) ? 700 : 500,
fontFamily: 'inherit', cursor: 'pointer',
display: 'inline-flex', alignItems: 'center', gap: 5,
whiteSpace: 'nowrap', marginRight: 8,
transition: isAlert ? 'none' : 'color 120ms ease, border-color 120ms ease',
animation: isAlert ? 'tab-alert 1.2s ease-in-out infinite' : 'none',
}}>
{TAB_ICON[tb.id] && {TAB_ICON[tb.id]} }
{tb.label}
{badge > 0 && !isAlert && (
{badge}
)}
)
})}
{/* Scrollable content */}
{activeTab === 'favorites' && (
)}
{activeTab === 'quick' &&
}
{activeTab === 'extras' &&
}
{activeTab === 'ingredients' &&
}
{activeTab === 'prefs' &&
}
{activeTab === 'quantity' && isDecimal &&
}
{activeTab === 'courses' && courses?.length > 0 &&
}
{activeTab === 'notes' &&
}
{activeTab === 'price_adjust' &&
}
{activeTab === 'summary' &&
}
{/* Footer: qty stepper + ADD */}
{isDecimal ? (
setActiveTab('quantity')}
style={{ display: 'inline-flex', alignItems: 'center', height: 52, borderRadius: 26, background: 'var(--bg3)', border: '1px solid var(--border)', overflow: 'hidden', flexShrink: 0, cursor: 'pointer', padding: '0 16px', gap: 6 }}
>
{fmtDecimalQty(qty, unitCfg)}
{unitCfg.label}
) : (
setQty(q => Math.max(1, q - 1))} style={{ width: 52, height: 52, border: 'none', background: 'transparent', fontSize: 22, fontWeight: 500, cursor: qty <= 1 ? 'default' : 'pointer', color: qty <= 1 ? 'var(--muted)' : 'var(--text)' }}>−
{qty}
setQty(q => q + 1)} style={{ width: 52, height: 52, border: 'none', background: 'transparent', fontSize: 22, fontWeight: 500, cursor: 'pointer', color: 'var(--text)' }}>+
)}
ADD
{money(totalPrice)}
>
)
}