// 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 (
)
}
/** 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 (
)
}
/** The conditions: all of them must hold (AND). */
export function ConditionList({ value, onChange, types, catalog, testid }) {
const { t } = useTranslation('manager')
const set = (i, v) => onChange(value.map((x, j) => (j === i ? v : x)))
return (