// Pieces the pricing tabs share (plan step 6.7): the colour and day pickers, the condition list (AND) and the target list (OR), a searchable // pick-several list, a tag picker, and the card a rule, a deal or a group shows as. import { useState } from 'react' import { ArrowDown, ArrowUp, Check, Pencil, Plus, Power, Trash2, X } from 'lucide-react' import { SALES_POINTS, normalizeSalesPoints } from '@xenia/access' import { latin, useFormat, useTranslation } from '@xenia/i18n' import { Button, Dropdown, IconButton, Input, MoneyInput, Select, cx } from '@xenia/ui' import { COLOURS } from './useCatalog' import { OLD_PLACEHOLDERS, WEEKDAYS, blankCondition, conditionComplete, toggleIn } from './pricingLogic' export function ColourPicker({ value, onChange, label }) { return (
{label}
{COLOURS.map(c => ( ))}
) } export function DayPicker({ value = [], onChange, testid }) { const { t } = useTranslation('manager') return (
{WEEKDAYS.map(d => ( ))}
) } /** Chips to pick several values (sales points, days…). */ export function Chips({ options, value, onChange, testid }) { return (
{options.map(o => ( ))}
) } /** One of a few choices as buttons (scope, action…). */ export function Segmented({ options, value, onChange, testid }) { return (
{options.map(o => ( ))}
) } /** A searchable list to pick several (products, categories, zones). */ export function PickSeveral({ items, value, onChange, testid }) { const { t } = useTranslation('manager') const [q, setQ] = useState('') const fold = v => latin(String(v)).toLowerCase() const shown = q.trim() ? items.filter(i => fold(i.plain ?? i.name).includes(fold(q.trim()))) : items const chosen = items.filter(i => value.includes(i.id)) return (
{chosen.length > 0 && (
{chosen.map(i => ( {i.plain ?? i.name} ))}
)} {items.length > 8 && setQ(e.target.value)} placeholder={t('pricing.search')} aria-label={t('pricing.search')} />}
) } export function TagPicker({ value, onChange, known }) { const { t } = useTranslation('manager') const [draft, setDraft] = useState('') const add = () => { const v = draft.trim(); if (v && !value.includes(v)) onChange([...value, v]); setDraft('') } return (
{known.length > 0 && ({ value: k, label: k }))} value={value} onChange={onChange} />}
setDraft(e.target.value)} placeholder={t('pricing.newTag')} aria-label={t('pricing.newTag')} onKeyDown={e => { if (e.key === 'Enter') { e.preventDefault(); add() } }} />
{value.filter(v => !known.includes(v)).length > 0 && ( !known.includes(v)).map(k => ({ value: k, label: k }))} value={value} onChange={onChange} /> )}
) } /** The products a rule or a deal looks at: any one of the rows (OR). */ export function TargetList({ value, onChange, types, catalog, testid }) { const { t } = useTranslation('manager') const set = (i, v) => onChange(value.map((x, j) => (j === i ? v : x))) return (
{value.map((tg, i) => (
set(i, blankCondition(e.target.value))} options={types.map(v => ({ value: v, label: t(`pricing.condition.types.${v}`) }))} />} onChange(value.filter((_, j) => j !== i))}>
set(i, v)} catalog={catalog} />
))}
) } function ConditionFields({ cond, onChange, catalog }) { const { t } = useTranslation('manager') const { t: tc } = useTranslation('common') const p = cond.params ?? {} const set = (k, v) => onChange({ ...cond, params: { ...p, [k]: v } }) const num = (k, low, step) => ( set(k, e.target.value === '' ? null : Number(e.target.value))} /> ) const pair = (type, a, b) => (
) switch (cond.condition_type) { case 'time_range': return <>{pair('time', 'from', 'to')}

{t('pricing.condition.timeHint')}

case 'date_range': return pair('date', 'from', 'to') case 'specific_date': return set('dates', v)} /> case 'day_of_week': return set('days', v)} /> case 'min_item_quantity': return case 'min_order_value': return ( ) case 'min_category_qty': return (
{num('min', 1, 1)} {t('pricing.condition.fromCategory')} set('price_group_id', e.target.value === '' ? null : Number(e.target.value))} placeholder={catalog.groups.length ? t('pricing.choose') : t('pricing.condition.noGroups')} options={catalog.groups.map(g => ({ value: g.id, label: g.name }))} /> ) case 'scene_active': return ( set('scene_id', v == null || v === '' ? null : Number(v))} placeholder={catalog.scenes.length ? t('pricing.choose') : t('pricing.condition.noScenes')} options={catalog.scenes.map(s => ({ value: s.id, label: s.name, dot: s.color || undefined }))} /> ) default: return null } } function DateList({ value, onChange }) { const { t } = useTranslation('manager') const { formatDate } = useFormat() const [draft, setDraft] = useState('') return (
setDraft(e.target.value)} aria-label={t('pricing.condition.date')} />
{value.length > 0 && ({ value: d, label: formatDate(d) }))} value={value} onChange={onChange} />}
) } /** A rule's, a deal's or a group's row: colour, name, badges, a summary, and its buttons. */ export function RuleCard({ colour, name, active, badges, summary, description, onToggle, onEdit, onDelete, onUp, onDown, testid, busy }) { const { t } = useTranslation('manager') return (
  • ) } /** The tab's head: what it is, and its "New" button. */ export function TabHead({ title, intro, action }) { return (

    {title}

    {intro}

    {action &&
    {action}
    }
    ) } /** "Fill in: …" under a dialog when something is missing. */ export function Missing({ problems, prefix }) { const { t } = useTranslation('manager') if (!problems.length) return null return

    {t('pricing.missing', { list: problems.map(p => t(`${prefix}.${p}`)).join(', ') })}

    }