// An order on the kitchen board (plan step 3.2b, from KdsPage.jsx): header coloured by how // late it is (age colours are device settings), item count, table / takeaway / delivery, // order number and status, the items (in columns, by course or by round), the order note // and the waiter. Tap selects it (buttons appear, items become tappable; it deselects // itself after 5 s without a touch); a long press on an unselected card shows quick actions. import { Fragment, useCallback, useEffect, useRef, useState } from 'react' import { Bike, Info, ShoppingBag, User, Utensils } from 'lucide-react' import { useTranslation } from '@xenia/i18n' import { courseGroups, minutesSince } from '../logic/board' import { BLOCK_GAP, BODY_PAD_B, BODY_PAD_H, BODY_PAD_T, CARD_FOOT_H_BASE, CARD_HEAD_H_BASE, CARD_SUB_H_BASE } from '../logic/layout' import { KDS } from '../theme' import { ActionBar, QuickActionBar } from './ActionBars' import ItemBlock from './ItemBlock' const HOLD_MS = 500 const IDLE_DESELECT_MS = 5000 const CHANNEL_ICONS = { here: Utensils, takeaway: ShoppingBag, delivery: Bike } function ChannelBadge({ orderType, tableName, fs }) { const { t } = useTranslation('terminal') const type = CHANNEL_ICONS[orderType] ? orderType : 'here' const Icon = CHANNEL_ICONS[type] const iconSz = Math.round(17 * fs) return ( {type === 'here' && tableName ? tableName : t(`kds.channel.${type}`)} ) } function headColours(age, colours) { if (age === 'done') return [colours.done, KDS.doneSub] if (age === 'future') return [KDS.futureHead, KDS.futureSubBg] if (age === 'green') return [colours.fresh, KDS.greenD] if (age === 'amber') return [colours.warning, KDS.amberD] return [colours.late, KDS.redD] } function glowFor(order, age) { if (age === 'done') return KDS.glowDone if (age === 'future') return KDS.glowFuture return order.kds_status === 'preparing' ? KDS.glowPreparing : KDS.glowPending } export default function OrderCard({ order, age, ageText, layout, focused, dimmed, settings, multiFilter, courses, now, onFocus, onStatus, onBumpItem, onPrint, onDecline, onItemDecline, onCallWaiter }) { const { t } = useTranslation('terminal') const fs = settings.fontScale const [headBg, subBg] = headColours(age.age, settings.colours) const glow = multiFilter ? glowFor(order, age.age) : null const itemCount = order.items.reduce((s, it) => s + it.quantity, 0) const waiter = order.waiters?.length ? order.waiters[0] : null const isFuture = age.age === 'future' // long press on an unselected card → quick actions const [quick, setQuick] = useState(false) const hold = useRef(null) const cancelHold = () => { if (hold.current) { clearTimeout(hold.current); hold.current = null } } const onPointerDown = () => { if (focused) return hold.current = setTimeout(() => { hold.current = null; setQuick(true) }, HOLD_MS) } // a selected card deselects itself after a few seconds without a touch const idle = useRef(null) const resetIdle = useCallback(() => { if (!focused) return if (idle.current) clearTimeout(idle.current) idle.current = setTimeout(() => onFocus(null), IDLE_DESELECT_MS) }, [focused, onFocus]) useEffect(() => { if (focused) resetIdle() else if (idle.current) { clearTimeout(idle.current); idle.current = null } return () => { if (idle.current) clearTimeout(idle.current) } }, [focused, resetIdle]) const item = it => ( { resetIdle(); onBumpItem(order.id, x.id) }} onDecline={focused ? x => { resetIdle(); onItemDecline(order.id, x.id, x.product_name) } : null} /> ) const column = (key, children) => (
{children}
) const deselect = e => { if (focused) { e.stopPropagation(); onFocus(null) } } let body if (settings.batchMode === 'grouped' && order._batches?.length > 1) { body = column('rounds', order._batches.map((batch, bi) => { const items = order.items.filter(it => (it._batchIndex ?? 0) === bi) if (!items.length) return null return (
{t('kds.card.batch', { n: bi + 1 })} {t('kds.age.minutes', { m: Math.max(0, minutesSince(batch.opened_at, now)) })}
{items.map(item)} ) })) } else { body = layout.cols.map((col, ci) => { const colItems = col.map(idx => order.items[idx]).filter(Boolean) if (settings.groupByCourse && courses?.length > 0) { return column(ci, courseGroups(colItems, courses).map((g, gi) => (
{g.course ? g.course.name : t('kds.card.noCourse')}
{g.items.map(item)}
))) } return column(ci, colItems.map(item)) }) } return (
{ e.stopPropagation(); cancelHold(); if (!quick) { onFocus(order.id); resetIdle() } }} onPointerDown={onPointerDown} onPointerUp={cancelHold} onPointerLeave={cancelHold} onPointerCancel={cancelHold} style={{ position: 'absolute', left: layout.x, top: layout.y, width: layout.w, height: layout.h, background: headBg, borderRadius: 10, overflow: 'hidden', boxShadow: focused ? `0 10px 24px rgba(0,0,0,.4), 0 0 0 4px rgba(47,127,240,.25)${glow ? `, 0 0 0 2px ${glow}40` : ''}` : `0 1px 2px rgba(0,0,0,.25), 0 6px 16px rgba(0,0,0,.22)${glow ? `, 0 0 12px 2px ${glow}55, 0 0 0 2px ${glow}44` : ''}`, outline: focused ? `2px solid ${KDS.accent}` : '2px solid transparent', outlineOffset: 2, display: 'flex', flexDirection: 'column', transform: focused ? 'scale(1.012)' : 'none', transition: 'box-shadow .15s, transform .15s, outline-color .15s', opacity: dimmed ? 0.42 : 1, filter: dimmed ? 'saturate(.7)' : 'none', zIndex: focused ? 60 : 1, cursor: 'pointer', userSelect: 'none', WebkitUserSelect: 'none', touchAction: 'none', }} >
{ageText} {t('kds.card.items', { count: itemCount })}
#{order.id} {t(`kds.card.status.${order.kds_status === 'done' || order.kds_status === 'preparing' ? order.kds_status : 'pending'}`)}
{body}
{order.notes && (
{order.notes}
)} {waiter && (
{waiter}
)} {quick && !focused && ( setQuick(false)} fs={fs} /> )} {focused && ( )}
) }