// The counter POS screen (plan steps 3.3a–e). Up to four modes, switched at the top left:
// - Sale: categories on the left, the product grid with a search, the quick-sale cart on the
// right (SaleCart: Charge → payment, 3.3b).
// - Tables: the zones on the left and the table list (TablesView); a table opens with the
// product grid again and the table's order on the right (TablePanel).
// - Online (when online orders are on and the cashier handles them): new / in progress /
// finished on the left, the orders (OnlineView) and the picked one (OnlinePanel). A new
// order rings (and again every 30 s while one waits for an answer) and shows a notice in any
// mode; the mode's badge counts the orders waiting.
// - Receipts: today's paid orders (the cashier's shift or everyone's) and the picked one
// (ReceiptPanel) to give money back for some or all of its items (3.3e).
// A tap adds a product (or opens its choices when it has preferences to pick); the (i) button
// checks its price without adding it. Every price is the backend's.
import { useEffect, useMemo, useState } from 'react'
import { Globe, Info, LayoutGrid, Receipt, Search, ShoppingBag, X } from 'lucide-react'
import { useFormat, useLanguage, useTranslation } from '@xenia/i18n'
import { useCan, useModule } from '@xenia/access'
import { EmptyState, IconButton, Input, Spinner, useToast } from '@xenia/ui'
import { useLiveEvent } from '../../device/context'
import { playChime } from './chime'
import { addLine, categoriesWithProducts, defaultSelection, needsChoices, productsIn, searchProducts, toLine, unitOf } from './logic/cart'
import { findOnline, ONLINE_LISTS } from './logic/online'
import { zoneCounts } from './logic/tables'
import OnlinePanel from './OnlinePanel'
import OnlineView from './OnlineView'
import ProductDialog from './ProductDialog'
import ReceiptPanel from './ReceiptPanel'
import ReceiptsView from './ReceiptsView'
import SaleCart from './SaleCart'
import TablePanel from './TablePanel'
import TablesView from './TablesView'
import { useMenu, useOnline, useReceipts, useTables } from './usePos'
const REMIND_MS = 30_000
export default function PosScreen() {
const { t } = useTranslation('terminal')
const { menu } = useMenu()
if (!menu) return