// A menu board's settings (plan step 5.6b): which products (everything, whole categories that stay
// up to date, single products, minus hidden ones), the board's own order of categories and products
// (arrows on what the board shows), badges, prices of a sales point, photos / descriptions, sold-out
// style, columns and pages, the look, and the widgets. `slide.menu` is the server's resolution of
// the draft (the editor asks for it as you change things).
// 2026-11-21 (owner review): sections with titles; what each line shows in fewer rows (the four
// switches on one); the layout: columns, how wide the list is and where it sits (left / centre /
// right), products per page, seconds per page.
// Owner review 2 (2026-11-21): a product hidden from the board stays in the list, greyed, with a red
// crossed eye (a green eye on the ones shown): a click shows / hides it; seconds per page explained;
// the text's look on one row. `board` mode: the same editor for a menu widget's list (no background,
// widgets, width or place; its own products per page).
// Owner review 3 (2026-11-21): the look part by part (MenuLook: headings, names, prices, dots,
// spacing, photos); a pencil beside each category and product on the board gives it a name for
// this board only (the catalogue keeps its own: the waiters' names stay as they are).
import { useEffect, useMemo, useState } from 'react'
import { AlignCenter, AlignLeft, AlignRight, ArrowDown, ArrowUp, Eye, EyeOff, Pencil, RotateCcw, X } from 'lucide-react'
import { MENU_LANGUAGES, SALES_POINTS } from '@xenia/access'
import { useFormat, useTranslation } from '@xenia/i18n'
import { Dropdown, Field, IconButton, Input, Segmented, Select, Switch } from '@xenia/ui'
import client from '../../api/client'
import { BADGES, boardOrder, moveGroup, moveItem, toggled } from './signageLogic'
import MenuLook from './MenuLook'
import { BackgroundField, Range, Section } from './SignageFields'
import WidgetsEditor from './WidgetsEditor'
let catalogue = null // categories and products, read once for every menu editor on the page
function useCatalogue() {
const [data, setData] = useState(catalogue || { cats: [], products: [] })
useEffect(() => {
if (catalogue) return
Promise.all([client.get('/api/products/categories'), client.get('/api/products/')]).then(([c, p]) => {
catalogue = { cats: c.data, products: p.data.filter(x => x.lifecycle_status === 'active' && !x.is_service_item) }
setData(catalogue)
}).catch(() => {})
}, [])
return data
}
export default function MenuEditor({ slide, onChange, media, onMedia, misfit = [], widget = null, onWidget, extras, board = false, testid = 'signage-menu-editor' }) {
const { t } = useTranslation('manager')
const { formatMoney } = useFormat()
const c = slide.content || {}
const setC = patch => onChange({ ...slide, content: { ...c, ...patch } })
const { cats, products } = useCatalogue()
const [q, setQ] = useState('')
const byId = useMemo(() => Object.fromEntries(products.map(p => [p.id, p])), [products])
const top = cats.filter(x => !x.parent_id)
const subsOf = id => cats.filter(x => x.parent_id === id)
const groups = slide.menu?.groups || []
const listed = new Set(groups.flatMap(g => g.items.map(i => i.id)))
const found = q.trim().length < 1 ? [] : products.filter(p => p.name.toLowerCase().includes(q.trim().toLowerCase()) && !listed.has(p.id)).slice(0, 8)
const reorder = next => setC(boardOrder(next))
const badges = c.badges || {}
const digits = v => Number(String(v).replace(/\D/g, ''))
const hidden = new Set(c.exclude_ids || [])
// this board's own names: empty = the catalogue's again
const rename = (key, id, name) => {
const next = { ...(c[key] || {}) }
if (name && name.trim()) next[String(id)] = name.trim()
else delete next[String(id)]
setC({ [key]: next })
}
return (
)
}
/**
* A category's or product's name on the board, with a pencil (shown on hover or focus) to give it a
* name for this board only; the catalogue's name shows under it then, with a button to go back to it.
*/
function OwnName({ name, original, onSave, className = '', testid }) {
const { t } = useTranslation('manager')
const [edit, setEdit] = useState(null)
if (edit != null) {
const done = () => { onSave(edit); setEdit(null) }
return (
setEdit(e.target.value)} onBlur={done}
onKeyDown={e => { if (e.key === 'Enter') done(); if (e.key === 'Escape') setEdit(null) }} />
)
}
return (
{name}
{original && {t('signage.menu.catalogueNameIs', { name: original })}}
setEdit(name)} data-testid={`${testid}-edit`}
className="opacity-0 group-hover/name:opacity-100 focus-visible:opacity-100 shrink-0">
{original && (
onSave('')} data-testid={`${testid}-reset`}
className="opacity-0 group-hover/name:opacity-100 focus-visible:opacity-100 shrink-0">
)}
)
}