{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "orders-queue-board",
  "type": "registry:component",
  "title": "Orders Queue Board",
  "description": "A kitchen queue with New, Preparing, Ready and Out columns. Drag cards or use the buttons and arrow keys to advance them, and hear a short chime when a new order arrives.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "ordering",
    "orders",
    "kitchen",
    "queue",
    "kanban",
    "restaurant",
    "dashboard"
  ],
  "docs": "https://hyperblur.dev/effects/orders-queue-board",
  "files": [
    {
      "path": "registry/hyperblur/orders-queue-board.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/orders-queue-board.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type QueueStatus = \"new\" | \"preparing\" | \"ready\" | \"dispatched\";\nexport type QueueChannel = \"delivery\" | \"pickup\" | \"table\";\n\nexport interface QueueItem {\n  name: string;\n  quantity?: number;\n}\n\nexport interface QueueOrder {\n  id: string;\n  number: string | number;\n  customer: string;\n  items: QueueItem[];\n  total: number;\n  channel: QueueChannel;\n  status: QueueStatus;\n  table?: string;\n  elapsedMinutes?: number;\n  placedAt?: string;\n}\n\nexport interface OrdersQueueLabels {\n  title: string;\n  subtitle: string;\n  new: string;\n  preparing: string;\n  ready: string;\n  dispatched: string;\n  delivery: string;\n  pickup: string;\n  table: string;\n  sound: string;\n  late: string;\n  lateCount: string;\n  minutes: string;\n  advanceNew: string;\n  advancePreparing: string;\n  advanceReady: string;\n  back: string;\n  print: string;\n  empty: string;\n  onTheWay: string;\n  pickedUp: string;\n  served: string;\n  moved: string;\n  newOrder: string;\n  more: string;\n}\n\nexport interface OrdersQueueBoardProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n  orders?: QueueOrder[];\n  defaultOrders?: QueueOrder[];\n  onStatusChange?: (id: string, status: QueueStatus, order: QueueOrder) => void;\n  onPrint?: (order: QueueOrder) => void;\n  soundEnabled?: boolean;\n  defaultSoundEnabled?: boolean;\n  onSoundChange?: (enabled: boolean) => void;\n  lateAfter?: number;\n  now?: Date | string;\n  currency?: string;\n  locale?: string;\n  labels?: Partial<OrdersQueueLabels>;\n  actions?: React.ReactNode;\n  accent?: string;\n}\n\nconst statuses: QueueStatus[] = [\"new\", \"preparing\", \"ready\", \"dispatched\"];\n\nconst statusColor: Record<QueueStatus, string> = {\n  new: \"var(--hb-oc1-accent)\",\n  preparing: \"#f5a524\",\n  ready: \"#3ccf91\",\n  dispatched: \"#8f8f8f\",\n};\n\nconst defaultLabels: OrdersQueueLabels = {\n  title: \"Orders\",\n  subtitle: \"Live queue\",\n  new: \"New\",\n  preparing: \"Preparing\",\n  ready: \"Ready\",\n  dispatched: \"Out / Picked up\",\n  delivery: \"Delivery\",\n  pickup: \"Pickup\",\n  table: \"Table\",\n  sound: \"Sound\",\n  late: \"Late\",\n  lateCount: \"{n} late\",\n  minutes: \"{n} min\",\n  advanceNew: \"Accept\",\n  advancePreparing: \"Ready\",\n  advanceReady: \"Hand off\",\n  back: \"Move back\",\n  print: \"Print\",\n  empty: \"No orders here\",\n  onTheWay: \"On the way\",\n  pickedUp: \"Picked up\",\n  served: \"Served\",\n  moved: \"Order {number} moved to {status}\",\n  newOrder: \"New order {number} from {customer}\",\n  more: \"+{n}\",\n};\n\nconst sampleOrders: QueueOrder[] = [\n  { id: \"o1048\", number: 1048, customer: \"Maya\", items: [{ name: \"Smash Double\", quantity: 2 }, { name: \"Crinkle Fries\" }, { name: \"Vanilla Shake\" }], total: 34.5, channel: \"delivery\", status: \"new\", elapsedMinutes: 1 },\n  { id: \"o1047\", number: 1047, customer: \"Jordan\", items: [{ name: \"Chicken Katsu Bowl\" }, { name: \"Miso Soup\" }], total: 18.75, channel: \"pickup\", status: \"new\", elapsedMinutes: 3 },\n  { id: \"o1045\", number: 1045, customer: \"Priya\", items: [{ name: \"Margherita, Large\" }, { name: \"Garlic Knots\", quantity: 6 }], total: 27.0, channel: \"delivery\", status: \"preparing\", elapsedMinutes: 24 },\n  { id: \"o1044\", number: 1044, customer: \"Leo\", items: [{ name: \"Fish Tacos\", quantity: 3 }, { name: \"Horchata\" }], total: 21.25, channel: \"table\", table: \"7\", status: \"preparing\", elapsedMinutes: 9 },\n  { id: \"o1042\", number: 1042, customer: \"Sam\", items: [{ name: \"Veggie Burrito\" }, { name: \"Chips and Salsa\" }], total: 15.5, channel: \"pickup\", status: \"ready\", elapsedMinutes: 14 },\n  { id: \"o1039\", number: 1039, customer: \"Ana\", items: [{ name: \"Pad Thai\" }, { name: \"Spring Rolls\", quantity: 4 }, { name: \"Thai Iced Tea\" }], total: 29.9, channel: \"delivery\", status: \"dispatched\", elapsedMinutes: 31 },\n];\n\nconst css = `\n.hb-oc1 {\n  --hb-oc1-accent: #2f7bff;\n  container-type: inline-size;\n  position: relative;\n  box-sizing: border-box;\n  width: 100%;\n  padding: 14px;\n  border: 1px solid #262626;\n  border-radius: 18px;\n  background: #0d0d0d;\n  color: #ededed;\n  font-family: inherit;\n  font-size: 13px;\n  line-height: 1.4;\n}\n.hb-oc1 *, .hb-oc1 *::before, .hb-oc1 *::after { box-sizing: border-box; }\n.hb-oc1-head {\n  display: flex;\n  flex-wrap: wrap;\n  align-items: center;\n  gap: 10px 12px;\n  margin-bottom: 12px;\n}\n.hb-oc1-title { display: flex; flex-direction: column; min-width: 0; margin-right: auto; }\n.hb-oc1-title strong { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }\n.hb-oc1-title span { display: inline-flex; align-items: center; gap: 6px; color: #8f8f8f; font-size: 12px; }\n.hb-oc1-live {\n  width: 7px;\n  height: 7px;\n  border-radius: 50%;\n  background: #3ccf91;\n  box-shadow: 0 0 0 0 rgba(60, 207, 145, 0.5);\n  animation: hb-oc1-live 2s ease-out infinite;\n}\n@keyframes hb-oc1-live {\n  0% { box-shadow: 0 0 0 0 rgba(60, 207, 145, 0.5); }\n  70%, 100% { box-shadow: 0 0 0 7px rgba(60, 207, 145, 0); }\n}\n.hb-oc1-stats { display: flex; flex-wrap: wrap; gap: 6px; }\n.hb-oc1-stat {\n  display: inline-flex;\n  align-items: center;\n  gap: 6px;\n  height: 26px;\n  padding: 0 9px;\n  border: 1px solid #262626;\n  border-radius: 999px;\n  background: #141414;\n  color: #a1a1a1;\n  font-size: 12px;\n  white-space: nowrap;\n}\n.hb-oc1-stat b { color: #ededed; font-weight: 600; font-variant-numeric: tabular-nums; }\n.hb-oc1-stat i { width: 6px; height: 6px; border-radius: 50%; font-style: normal; }\n.hb-oc1-stat[data-late=\"true\"] { border-color: rgba(255, 92, 92, 0.35); background: rgba(255, 92, 92, 0.08); color: #ff8a8a; }\n.hb-oc1-stat[data-late=\"true\"] b { color: #ffb0b0; }\n.hb-oc1-tools { display: flex; align-items: center; gap: 8px; }\n.hb-oc1-sound {\n  display: inline-flex;\n  align-items: center;\n  gap: 8px;\n  height: 30px;\n  padding: 0 10px 0 9px;\n  border: 1px solid #262626;\n  border-radius: 999px;\n  background: #141414;\n  color: #a1a1a1;\n  font: inherit;\n  font-size: 12px;\n  cursor: pointer;\n  transition: border-color 0.18s ease, color 0.18s ease;\n}\n.hb-oc1-sound:hover { border-color: #3a3a3a; color: #ededed; }\n.hb-oc1-sound svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }\n.hb-oc1-track {\n  position: relative;\n  width: 26px;\n  height: 15px;\n  border-radius: 999px;\n  background: #2a2a2a;\n  transition: background-color 0.2s ease;\n}\n.hb-oc1-track::after {\n  content: \"\";\n  position: absolute;\n  top: 2px;\n  left: 2px;\n  width: 11px;\n  height: 11px;\n  border-radius: 50%;\n  background: #ededed;\n  transition: transform 0.22s cubic-bezier(0.3, 1.4, 0.5, 1);\n}\n.hb-oc1-sound[aria-checked=\"true\"] { color: #ededed; }\n.hb-oc1-sound[aria-checked=\"true\"] .hb-oc1-track { background: var(--hb-oc1-accent); }\n.hb-oc1-sound[aria-checked=\"true\"] .hb-oc1-track::after { transform: translateX(11px); }\n.hb-oc1-cols {\n  display: grid;\n  grid-auto-flow: column;\n  grid-auto-columns: minmax(220px, 80%);\n  gap: 10px;\n  overflow-x: auto;\n  scroll-snap-type: x mandatory;\n  scrollbar-width: thin;\n  padding-bottom: 2px;\n}\n@container (min-width: 720px) {\n  .hb-oc1-cols {\n    grid-auto-flow: row;\n    grid-template-columns: repeat(4, minmax(0, 1fr));\n    overflow: visible;\n  }\n}\n.hb-oc1-col {\n  display: flex;\n  flex-direction: column;\n  min-width: 0;\n  padding: 8px;\n  border: 1px solid #1f1f1f;\n  border-radius: 14px;\n  background: #111111;\n  scroll-snap-align: start;\n  transition: border-color 0.18s ease, background-color 0.18s ease;\n}\n.hb-oc1-col[data-over=\"true\"] {\n  border-color: color-mix(in srgb, var(--hb-oc1-accent) 55%, #262626);\n  background: color-mix(in srgb, var(--hb-oc1-accent) 7%, #111111);\n}\n.hb-oc1-colhead {\n  display: flex;\n  align-items: center;\n  gap: 7px;\n  padding: 2px 4px 8px;\n  color: #a1a1a1;\n  font-size: 12px;\n  font-weight: 500;\n  white-space: nowrap;\n}\n.hb-oc1-colhead i { width: 7px; height: 7px; border-radius: 50%; flex: none; font-style: normal; }\n.hb-oc1-colhead span { overflow: hidden; text-overflow: ellipsis; }\n.hb-oc1-colhead b {\n  margin-left: auto;\n  min-width: 20px;\n  padding: 1px 6px;\n  border-radius: 999px;\n  background: #1c1c1c;\n  color: #ededed;\n  font-size: 11px;\n  font-weight: 600;\n  text-align: center;\n  font-variant-numeric: tabular-nums;\n}\n.hb-oc1-list { display: flex; flex-direction: column; gap: 8px; min-height: 96px; margin: 0; padding: 0; list-style: none; }\n.hb-oc1-empty {\n  display: grid;\n  place-items: center;\n  min-height: 96px;\n  border: 1px dashed #262626;\n  border-radius: 10px;\n  color: #6f6f6f;\n  font-size: 12px;\n}\n.hb-oc1-card {\n  position: relative;\n  padding: 10px 11px 10px 12px;\n  border: 1px solid #262626;\n  border-radius: 12px;\n  background: #171717;\n  outline: none;\n  cursor: grab;\n  user-select: none;\n  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;\n}\n.hb-oc1-card:hover { border-color: #333333; }\n.hb-oc1-card:focus-visible { outline: 2px solid var(--hb-oc1-accent); outline-offset: 2px; }\n.hb-oc1-card::before {\n  content: \"\";\n  position: absolute;\n  top: 10px;\n  bottom: 10px;\n  left: -1px;\n  width: 2px;\n  border-radius: 2px;\n  background: var(--hb-oc1-tone);\n  opacity: 0.9;\n}\n.hb-oc1-card[data-late=\"true\"] { border-color: rgba(255, 92, 92, 0.4); background: linear-gradient(180deg, rgba(255, 92, 92, 0.07), #171717 60%); }\n.hb-oc1-card[data-late=\"true\"]::before { background: #ff5c5c; }\n.hb-oc1-card[data-drag=\"true\"] {\n  z-index: 5;\n  cursor: grabbing;\n  border-color: color-mix(in srgb, var(--hb-oc1-accent) 60%, #333333);\n  box-shadow: 0 18px 40px -12px rgba(0, 0, 0, 0.8);\n  transition: none;\n}\n.hb-oc1-card[data-fresh=\"true\"] {\n  animation: hb-oc1-in 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.2), hb-oc1-glow 2.4s ease-out;\n}\n@keyframes hb-oc1-in {\n  from { opacity: 0; transform: translateY(-12px) scale(0.96); }\n  to { opacity: 1; transform: none; }\n}\n@keyframes hb-oc1-glow {\n  0%, 30% { box-shadow: 0 0 0 1px var(--hb-oc1-accent), 0 0 24px -4px color-mix(in srgb, var(--hb-oc1-accent) 70%, transparent); }\n  100% { box-shadow: 0 0 0 1px transparent, 0 0 0 0 transparent; }\n}\n.hb-oc1-row { display: flex; align-items: center; gap: 6px; min-width: 0; }\n.hb-oc1-grip {\n  display: inline-grid;\n  place-items: center;\n  width: 14px;\n  height: 18px;\n  margin-left: -4px;\n  color: #5a5a5a;\n  touch-action: none;\n  cursor: grab;\n}\n.hb-oc1-grip svg { width: 10px; height: 14px; fill: currentColor; }\n.hb-oc1-num { font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }\n.hb-oc1-pill {\n  flex: none;\n  display: inline-flex;\n  align-items: center;\n  gap: 4px;\n  height: 19px;\n  padding: 0 7px;\n  border-radius: 999px;\n  background: #222222;\n  color: #c9c9c9;\n  font-size: 11px;\n  white-space: nowrap;\n}\n.hb-oc1-pill svg { width: 11px; height: 11px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }\n.hb-oc1-pill[data-channel=\"delivery\"] { background: rgba(127, 179, 255, 0.12); color: #9cc4ff; }\n.hb-oc1-pill[data-channel=\"pickup\"] { background: rgba(245, 165, 36, 0.12); color: #f7bf5e; }\n.hb-oc1-pill[data-channel=\"table\"] { background: rgba(60, 207, 145, 0.12); color: #6fdcaa; }\n.hb-oc1-time {\n  display: inline-flex;\n  align-items: center;\n  gap: 4px;\n  margin-left: auto;\n  color: #8f8f8f;\n  font-size: 11.5px;\n  white-space: nowrap;\n  font-variant-numeric: tabular-nums;\n}\n.hb-oc1-time svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }\n.hb-oc1-card[data-late=\"true\"] .hb-oc1-time { color: #ff8a8a; font-weight: 600; }\n.hb-oc1-latetag {\n  padding: 1px 6px;\n  border-radius: 999px;\n  background: #ff5c5c;\n  color: #1a0505;\n  font-size: 10px;\n  font-weight: 700;\n  letter-spacing: 0.02em;\n  text-transform: uppercase;\n  animation: hb-oc1-blink 1.6s ease-in-out infinite;\n}\n@keyframes hb-oc1-blink { 50% { opacity: 0.55; } }\n.hb-oc1-who { margin: 6px 0 3px; }\n.hb-oc1-name { flex: 1 1 auto; min-width: 0; margin: 0; overflow: hidden; color: #ededed; font-size: 13.5px; font-weight: 500; white-space: nowrap; text-overflow: ellipsis; }\n.hb-oc1-items {\n  display: -webkit-box;\n  margin: 0 0 9px;\n  overflow: hidden;\n  color: #8f8f8f;\n  font-size: 12px;\n  line-height: 1.45;\n  -webkit-box-orient: vertical;\n  -webkit-line-clamp: 2;\n}\n.hb-oc1-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }\n.hb-oc1-total { margin-right: auto; font-weight: 600; font-variant-numeric: tabular-nums; }\n.hb-oc1-icon, .hb-oc1-adv {\n  display: inline-flex;\n  align-items: center;\n  justify-content: center;\n  height: 26px;\n  margin: 0;\n  border: 1px solid #2c2c2c;\n  border-radius: 8px;\n  background: #1d1d1d;\n  color: #a1a1a1;\n  font: inherit;\n  font-size: 12px;\n  cursor: pointer;\n  transition: border-color 0.16s ease, background-color 0.16s ease, color 0.16s ease, transform 0.12s ease;\n}\n.hb-oc1-icon { width: 26px; padding: 0; }\n.hb-oc1-icon svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }\n.hb-oc1-icon:hover { border-color: #3a3a3a; color: #ededed; }\n.hb-oc1-adv {\n  gap: 4px;\n  padding: 0 9px;\n  border-color: color-mix(in srgb, var(--hb-oc1-tone) 45%, #2c2c2c);\n  background: color-mix(in srgb, var(--hb-oc1-tone) 16%, #1d1d1d);\n  color: #ededed;\n  font-weight: 500;\n  white-space: nowrap;\n}\n.hb-oc1-adv svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }\n.hb-oc1-adv:hover { background: color-mix(in srgb, var(--hb-oc1-tone) 26%, #1d1d1d); }\n.hb-oc1-icon:active, .hb-oc1-adv:active { transform: scale(0.95); }\n.hb-oc1-icon:focus-visible, .hb-oc1-adv:focus-visible, .hb-oc1-sound:focus-visible { outline: 2px solid var(--hb-oc1-accent); outline-offset: 2px; }\n.hb-oc1-done { display: inline-flex; align-items: center; gap: 4px; color: #8f8f8f; font-size: 12px; white-space: nowrap; }\n.hb-oc1-done svg { width: 13px; height: 13px; fill: none; stroke: #3ccf91; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }\n.hb-oc1-sr {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  overflow: hidden;\n  clip: rect(0 0 0 0);\n  white-space: nowrap;\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-oc1 *, .hb-oc1 *::before, .hb-oc1 *::after { animation: none !important; transition: none !important; }\n}\n`;\n\nfunction fill(template: string, values: Record<string, string | number>) {\n  return template.replace(/\\{(\\w+)\\}/g, (match, key: string) => (key in values ? String(values[key]) : match));\n}\n\nfunction parseTime(value: Date | string | undefined) {\n  if (value === undefined) return null;\n  const time = typeof value === \"string\" ? Date.parse(value) : value.getTime();\n  return Number.isNaN(time) ? null : time;\n}\n\ntype AudioWindow = Window & { webkitAudioContext?: typeof AudioContext };\n\nfunction playChime(ctx: AudioContext) {\n  if (ctx.state === \"suspended\") void ctx.resume();\n  const start = ctx.currentTime + 0.02;\n  const tones: [number, number][] = [[880, 0], [1318.5, 0.17]];\n  for (const [frequency, delay] of tones) {\n    const osc = ctx.createOscillator();\n    const gain = ctx.createGain();\n    osc.type = \"sine\";\n    osc.frequency.value = frequency;\n    gain.gain.setValueAtTime(0.0001, start + delay);\n    gain.gain.exponentialRampToValueAtTime(0.2, start + delay + 0.02);\n    gain.gain.exponentialRampToValueAtTime(0.0001, start + delay + 0.55);\n    osc.connect(gain);\n    gain.connect(ctx.destination);\n    osc.start(start + delay);\n    osc.stop(start + delay + 0.6);\n  }\n}\n\nfunction ChannelIcon({ channel }: { channel: QueueChannel }) {\n  if (channel === \"delivery\")\n    return (\n      <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n        <path d=\"M3 7h11v8H3zM14 10h4l3 3v2h-7\" />\n        <circle cx=\"7\" cy=\"17\" r=\"2\" />\n        <circle cx=\"17\" cy=\"17\" r=\"2\" />\n      </svg>\n    );\n  if (channel === \"pickup\")\n    return (\n      <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n        <path d=\"M5 8h14l-1.2 12H6.2zM9 8V6a3 3 0 0 1 6 0v2\" />\n      </svg>\n    );\n  return (\n    <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n      <path d=\"M4 9h16M6 9v10M18 9v10M8 5h8\" />\n    </svg>\n  );\n}\n\nexport function OrdersQueueBoard({\n  orders,\n  defaultOrders = sampleOrders,\n  onStatusChange,\n  onPrint,\n  soundEnabled,\n  defaultSoundEnabled = true,\n  onSoundChange,\n  lateAfter = 20,\n  now,\n  currency = \"USD\",\n  locale = \"en-US\",\n  labels,\n  actions,\n  accent = \"#2f7bff\",\n  className,\n  style,\n  ...rest\n}: OrdersQueueBoardProps) {\n  const t = { ...defaultLabels, ...labels };\n  const [internal, setInternal] = React.useState<QueueOrder[]>(defaultOrders);\n  const list = orders ?? internal;\n  const [soundState, setSoundState] = React.useState(defaultSoundEnabled);\n  const sound = soundEnabled ?? soundState;\n  const [seen, setSeen] = React.useState<string[]>(() => list.map((o) => o.id));\n  const [fresh, setFresh] = React.useState<string[]>([]);\n  const [chimeCount, setChimeCount] = React.useState(0);\n  const [announce, setAnnounce] = React.useState(\"\");\n  const [clock, setClock] = React.useState<number | null>(null);\n  const [drag, setDrag] = React.useState<{ id: string; dx: number; dy: number; over: QueueStatus | null } | null>(null);\n  const audioRef = React.useRef<AudioContext | null>(null);\n  const soundRef = React.useRef(sound);\n  const colRefs = React.useRef<Partial<Record<QueueStatus, HTMLDivElement | null>>>({});\n  const pointer = React.useRef<{ id: string; pointerId: number; x: number; y: number; active: boolean; over: QueueStatus | null } | null>(null);\n\n  const money = React.useMemo(() => new Intl.NumberFormat(locale, { style: \"currency\", currency }), [locale, currency]);\n\n  const newcomers = list.filter((o) => !seen.includes(o.id));\n  if (newcomers.length) {\n    setSeen([...seen, ...newcomers.map((o) => o.id)]);\n    const incoming = newcomers.filter((o) => o.status === \"new\");\n    if (incoming.length) {\n      setFresh((prev) => [...prev, ...incoming.map((o) => o.id)]);\n      setChimeCount((c) => c + 1);\n      const last = incoming[incoming.length - 1];\n      setAnnounce(fill(t.newOrder, { number: last.number, customer: last.customer }));\n    }\n  }\n\n  React.useEffect(() => {\n    soundRef.current = sound;\n  }, [sound]);\n\n  const ensureAudio = React.useCallback(() => {\n    if (audioRef.current || typeof window === \"undefined\") return audioRef.current;\n    const Ctor = window.AudioContext ?? (window as AudioWindow).webkitAudioContext;\n    if (!Ctor) return null;\n    try {\n      audioRef.current = new Ctor();\n    } catch {\n      audioRef.current = null;\n    }\n    return audioRef.current;\n  }, []);\n\n  React.useEffect(() => {\n    const unlock = () => {\n      if (soundRef.current) ensureAudio();\n    };\n    document.addEventListener(\"pointerdown\", unlock, true);\n    document.addEventListener(\"keydown\", unlock, true);\n    return () => {\n      document.removeEventListener(\"pointerdown\", unlock, true);\n      document.removeEventListener(\"keydown\", unlock, true);\n    };\n  }, [ensureAudio]);\n\n  React.useEffect(() => {\n    if (!chimeCount || !soundRef.current || !audioRef.current) return;\n    playChime(audioRef.current);\n  }, [chimeCount]);\n\n  React.useEffect(() => {\n    if (!fresh.length) return;\n    const timer = window.setTimeout(() => setFresh([]), 2600);\n    return () => window.clearTimeout(timer);\n  }, [fresh]);\n\n  const needsClock = now === undefined && list.some((o) => o.elapsedMinutes === undefined && o.placedAt);\n  React.useEffect(() => {\n    if (!needsClock) return;\n    const tick = () => setClock(Date.now());\n    const first = window.setTimeout(tick, 0);\n    const timer = window.setInterval(tick, 30000);\n    return () => {\n      window.clearTimeout(first);\n      window.clearInterval(timer);\n    };\n  }, [needsClock]);\n\n  React.useEffect(() => () => {\n    void audioRef.current?.close();\n  }, []);\n\n  const reference = parseTime(now) ?? clock;\n  const elapsedOf = (o: QueueOrder) => {\n    if (o.elapsedMinutes !== undefined) return o.elapsedMinutes;\n    const placed = parseTime(o.placedAt);\n    if (placed === null || reference === null) return null;\n    return Math.max(0, Math.floor((reference - placed) / 60000));\n  };\n\n  const move = (order: QueueOrder, to: QueueStatus) => {\n    if (order.status === to) return;\n    if (orders === undefined) setInternal((prev) => prev.map((o) => (o.id === order.id ? { ...o, status: to } : o)));\n    onStatusChange?.(order.id, to, { ...order, status: to });\n    setAnnounce(fill(t.moved, { number: order.number, status: t[to] }));\n  };\n\n  const toggleSound = () => {\n    const next = !sound;\n    if (soundEnabled === undefined) setSoundState(next);\n    onSoundChange?.(next);\n    if (next) {\n      const ctx = ensureAudio();\n      if (ctx) playChime(ctx);\n    }\n  };\n\n  const columnAt = (x: number) => {\n    for (const s of statuses) {\n      const el = colRefs.current[s];\n      if (!el) continue;\n      const r = el.getBoundingClientRect();\n      if (x >= r.left && x <= r.right) return s;\n    }\n    return null;\n  };\n\n  const onPointerDown = (e: React.PointerEvent<HTMLLIElement>, order: QueueOrder) => {\n    if (e.button !== 0) return;\n    const target = e.target as HTMLElement;\n    if (target.closest(\"button\")) return;\n    if (e.pointerType !== \"mouse\" && !target.closest(\"[data-grip]\")) return;\n    pointer.current = { id: order.id, pointerId: e.pointerId, x: e.clientX, y: e.clientY, active: false, over: null };\n    e.currentTarget.setPointerCapture(e.pointerId);\n  };\n\n  const onPointerMove = (e: React.PointerEvent<HTMLLIElement>) => {\n    const p = pointer.current;\n    if (!p || p.pointerId !== e.pointerId) return;\n    const dx = e.clientX - p.x;\n    const dy = e.clientY - p.y;\n    if (!p.active && Math.hypot(dx, dy) < 5) return;\n    p.active = true;\n    p.over = columnAt(e.clientX);\n    setDrag({ id: p.id, dx, dy, over: p.over });\n  };\n\n  const onPointerEnd = (e: React.PointerEvent<HTMLLIElement>, order: QueueOrder, cancel: boolean) => {\n    const p = pointer.current;\n    if (!p || p.pointerId !== e.pointerId) return;\n    pointer.current = null;\n    if (e.currentTarget.hasPointerCapture(e.pointerId)) e.currentTarget.releasePointerCapture(e.pointerId);\n    if (p.active && !cancel && p.over) move(order, p.over);\n    setDrag(null);\n  };\n\n  const onCardKey = (e: React.KeyboardEvent<HTMLLIElement>, order: QueueOrder) => {\n    if (e.target !== e.currentTarget) return;\n    const index = statuses.indexOf(order.status);\n    if (e.key === \"ArrowRight\" && index < statuses.length - 1) {\n      e.preventDefault();\n      move(order, statuses[index + 1]);\n    } else if (e.key === \"ArrowLeft\" && index > 0) {\n      e.preventDefault();\n      move(order, statuses[index - 1]);\n    }\n  };\n\n  const lateCount = list.filter((o) => o.status !== \"dispatched\" && (elapsedOf(o) ?? 0) >= lateAfter).length;\n  const advanceLabel: Record<QueueStatus, string> = { new: t.advanceNew, preparing: t.advancePreparing, ready: t.advanceReady, dispatched: \"\" };\n\n  return (\n    <div className={[\"hb-oc1\", className].filter(Boolean).join(\" \")} style={{ \"--hb-oc1-accent\": accent, ...style } as React.CSSProperties} {...rest}>\n      <style href=\"hb-orders-queue-board\" precedence=\"default\">{css}</style>\n      <div className=\"hb-oc1-head\">\n        <div className=\"hb-oc1-title\">\n          <strong>{t.title}</strong>\n          <span>\n            <i className=\"hb-oc1-live\" aria-hidden=\"true\" />\n            {t.subtitle}\n          </span>\n        </div>\n        <div className=\"hb-oc1-stats\">\n          {statuses.slice(0, 3).map((s) => (\n            <span key={s} className=\"hb-oc1-stat\">\n              <i style={{ background: statusColor[s] }} aria-hidden=\"true\" />\n              {t[s]} <b>{list.filter((o) => o.status === s).length}</b>\n            </span>\n          ))}\n          {lateCount > 0 && (\n            <span className=\"hb-oc1-stat\" data-late=\"true\">\n              <b>{fill(t.lateCount, { n: lateCount })}</b>\n            </span>\n          )}\n        </div>\n        <div className=\"hb-oc1-tools\">\n          {actions}\n          <button type=\"button\" role=\"switch\" aria-checked={sound} className=\"hb-oc1-sound\" onClick={toggleSound}>\n            <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n              <path d=\"M4 10v4h3l5 4V6L7 10z\" />\n              {sound ? <path d=\"M16 9a4 4 0 0 1 0 6M18.5 6.5a7.5 7.5 0 0 1 0 11\" /> : <path d=\"M16 10l4 4M20 10l-4 4\" />}\n            </svg>\n            {t.sound}\n            <span className=\"hb-oc1-track\" aria-hidden=\"true\" />\n          </button>\n        </div>\n      </div>\n      <div className=\"hb-oc1-cols\">\n        {statuses.map((status, index) => {\n          const items = list.filter((o) => o.status === status);\n          return (\n            <div\n              key={status}\n              ref={(el) => {\n                colRefs.current[status] = el;\n              }}\n              className=\"hb-oc1-col\"\n              data-over={drag?.over === status && list.find((o) => o.id === drag.id)?.status !== status ? \"true\" : undefined}\n              role=\"group\"\n              aria-label={`${t[status]}, ${items.length}`}\n            >\n              <div className=\"hb-oc1-colhead\">\n                <i style={{ background: statusColor[status] }} aria-hidden=\"true\" />\n                <span>{t[status]}</span>\n                <b>{items.length}</b>\n              </div>\n              {items.length === 0 ? (\n                <div className=\"hb-oc1-empty\">{t.empty}</div>\n              ) : (\n                <ul className=\"hb-oc1-list\">\n                  {items.map((order) => {\n                    const elapsed = elapsedOf(order);\n                    const late = status !== \"dispatched\" && elapsed !== null && elapsed >= lateAfter;\n                    const dragging = drag?.id === order.id;\n                    const summary = order.items.slice(0, 3).map((it) => ((it.quantity ?? 1) > 1 ? `${it.quantity}× ${it.name}` : it.name)).join(\", \");\n                    const extra = order.items.length - 3;\n                    const channelLabel = order.channel === \"table\" && order.table ? `${t.table} ${order.table}` : t[order.channel];\n                    const doneLabel = order.channel === \"delivery\" ? t.onTheWay : order.channel === \"table\" ? t.served : t.pickedUp;\n                    return (\n                      <li\n                        key={order.id}\n                        className=\"hb-oc1-card\"\n                        tabIndex={0}\n                        aria-label={`#${order.number}, ${order.customer}, ${money.format(order.total)}, ${channelLabel}${late ? `, ${t.late}` : \"\"}`}\n                        aria-keyshortcuts=\"ArrowLeft ArrowRight\"\n                        data-late={late ? \"true\" : undefined}\n                        data-fresh={fresh.includes(order.id) ? \"true\" : undefined}\n                        data-drag={dragging ? \"true\" : undefined}\n                        style={\n                          {\n                            \"--hb-oc1-tone\": statusColor[status],\n                            transform: dragging ? `translate(${drag.dx.toFixed(1)}px, ${drag.dy.toFixed(1)}px) rotate(1.5deg)` : undefined,\n                          } as React.CSSProperties\n                        }\n                        onPointerDown={(e) => onPointerDown(e, order)}\n                        onPointerMove={onPointerMove}\n                        onPointerUp={(e) => onPointerEnd(e, order, false)}\n                        onPointerCancel={(e) => onPointerEnd(e, order, true)}\n                        onKeyDown={(e) => onCardKey(e, order)}\n                      >\n                        <div className=\"hb-oc1-row\">\n                          <span className=\"hb-oc1-grip\" data-grip=\"\" aria-hidden=\"true\">\n                            <svg viewBox=\"0 0 10 14\">\n                              <circle cx=\"3\" cy=\"3\" r=\"1.3\" />\n                              <circle cx=\"7\" cy=\"3\" r=\"1.3\" />\n                              <circle cx=\"3\" cy=\"7\" r=\"1.3\" />\n                              <circle cx=\"7\" cy=\"7\" r=\"1.3\" />\n                              <circle cx=\"3\" cy=\"11\" r=\"1.3\" />\n                              <circle cx=\"7\" cy=\"11\" r=\"1.3\" />\n                            </svg>\n                          </span>\n                          <span className=\"hb-oc1-num\">#{order.number}</span>\n                          {late && <span className=\"hb-oc1-latetag\">{t.late}</span>}\n                          {elapsed !== null && (\n                            <span className=\"hb-oc1-time\">\n                              <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n                                <circle cx=\"12\" cy=\"12\" r=\"8.5\" />\n                                <path d=\"M12 7.5V12l3 2\" />\n                              </svg>\n                              {fill(t.minutes, { n: elapsed })}\n                            </span>\n                          )}\n                        </div>\n                        <div className=\"hb-oc1-row hb-oc1-who\">\n                          <p className=\"hb-oc1-name\">{order.customer}</p>\n                          <span className=\"hb-oc1-pill\" data-channel={order.channel}>\n                            <ChannelIcon channel={order.channel} />\n                            {channelLabel}\n                          </span>\n                        </div>\n                        <p className=\"hb-oc1-items\">\n                          {summary}\n                          {extra > 0 ? ` ${fill(t.more, { n: extra })}` : \"\"}\n                        </p>\n                        <div className=\"hb-oc1-foot\">\n                          <span className=\"hb-oc1-total\">{money.format(order.total)}</span>\n                          {onPrint && (\n                            <button type=\"button\" className=\"hb-oc1-icon\" aria-label={`${t.print} #${order.number}`} title={t.print} onClick={() => onPrint(order)}>\n                              <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n                                <path d=\"M7 9V4h10v5M7 17H5a1 1 0 0 1-1-1v-5a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v5a1 1 0 0 1-1 1h-2M7 14h10v6H7z\" />\n                              </svg>\n                            </button>\n                          )}\n                          {index > 0 && (\n                            <button type=\"button\" className=\"hb-oc1-icon\" aria-label={`${t.back} #${order.number}`} title={t.back} onClick={() => move(order, statuses[index - 1])}>\n                              <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n                                <path d=\"M14.5 6 8.5 12l6 6\" />\n                              </svg>\n                            </button>\n                          )}\n                          {index < statuses.length - 1 ? (\n                            <button type=\"button\" className=\"hb-oc1-adv\" onClick={() => move(order, statuses[index + 1])}>\n                              {advanceLabel[status]}\n                              <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n                                <path d=\"M9.5 6l6 6-6 6\" />\n                              </svg>\n                            </button>\n                          ) : (\n                            <span className=\"hb-oc1-done\">\n                              <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n                                <path d=\"M5 12.5l4.5 4.5L19 7.5\" />\n                              </svg>\n                              {doneLabel}\n                            </span>\n                          )}\n                        </div>\n                      </li>\n                    );\n                  })}\n                </ul>\n              )}\n            </div>\n          );\n        })}\n      </div>\n      <div className=\"hb-oc1-sr\" aria-live=\"polite\">\n        {announce}\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}