// The pieces of a floor plan as SVG (plan step 6.8): the floor (outline, grid, background
// picture), the walls / bar / labels / areas, and a table with its chairs and what it shows.
// Colours are @xenia/ui tokens (CSS variables), so the same drawing works in every app.
import { chairs, durationText, itemFontSize, outlineOf, peopleText, pointsAttr, TONES, toneOf } from './geometry.js'
/** The floor: background picture, the floor's shape, and the grid (when asked). */
export function Floor({ plan, showGrid = false, mediaBase = '' }) {
const pts = pointsAttr(outlineOf(plan))
const g = plan.grid_size
const clip = `floor-clip-${plan.id ?? 'new'}`
return (
{showGrid && g > 0 && (
)}
{plan.background?.full && (
)}
{showGrid && g > 0 && }
)
}
const ITEM_LOOK = {
wall: { fill: 'var(--x-ink-2)', stroke: 'none' },
bar: { fill: 'var(--x-surface-3)', stroke: 'var(--x-ink-3)' },
label: { fill: 'transparent', stroke: 'none' }, // transparent, not none: a label can be clicked
area: { fill: 'var(--x-surface-2)', stroke: 'var(--x-line-strong)', dash: '8 6' },
}
/**
* A wall, the bar, a label or an area. An area may have a colour (drawn see-through, 2026-11-20);
* `corner`: its name is covered by tables, so it shows in the top-left corner as well.
*/
export function Item({ item, selected = false, label, corner = false, ...rest }) {
const look = ITEM_LOOK[item.kind] ?? ITEM_LOOK.area
const w = item.width
const h = item.height
const text = item.text || (item.kind === 'bar' ? label : '')
const colour = item.kind === 'area' && item.color ? item.color : null
const fs = text ? itemFontSize(item, text) : 0
return (
{item.kind === 'label' && selected && }
{text && (
{text}
)}
{text && corner && (
{text}
)}
)
}
/** A small person (for seats / guests): drawn, so it looks the same everywhere. */
function Person({ x, y, size, color }) {
const r = size / 2
return (
)
}
/**
* A table: its shape, chairs for its seats, and (live) its name, guests / seats, time open,
* waiters and a "ready" count. `now` (ms) moves the clock.
*/
export function TableShape({ table, live = true, selected = false, now = Date.now(), ...rest }) {
const tone = TONES[live ? toneOf(table) : 'free']
const w = table.width || 80
const h = table.height || 80
const rot = table.rotation || 0
const o = live ? table.order : null
const fs = Math.max(11, Math.min(22, Math.min(w, h) * 0.24))
const lines = [table.name]
const second = o ? `${o.guests ?? '–'}/${table.seats ?? '–'}` : table.seats ? `${table.seats}` : ''
const third = o ? [durationText(o.opened_at ? Math.max(0, Math.floor((now - new Date(o.opened_at).getTime()) / 60000)) : null), peopleText(o.people)].filter(Boolean).join(' · ') : ''
return (
{chairs(table.shape, w, h, table.seats).map(([cx, cy], i) => (
))}
{table.shape === 'round'
?
: }
{lines[0]}
{second && (
{second}
)}
{third && {third}}
{o?.ready > 0 && (
{o.ready}
)}
)
}