import {getCardComponentData} from "../cards";
import {CardRenderer, CardRendererContext} from "../CardRenderers";
import {ComponentMeta} from "../ComponentsMeta";
import {__, CouponsPlus} from "../../globals";
import {AmountValidatorOptions} from "./filterinterfaces";
import {FieldType} from "../fields";
import {usingTestableOptions} from "./CardHelpers";
import {iconWithClassName} from "../IconWithClassName";
import {NumberProps} from "../fields/Number";
import {getWithCurrency} from "../fields/Currency";
import {ComponentCategory} from "../components";
import {RowOptions} from "./Fields/RowOptions";
export type ItemPriceOptions = AmountValidatorOptions
const type = CouponsPlus?.components?.filters?.ItemPrice?.type || 'ItemPrice'
export const ItemPriceMeta: ComponentMeta = {
id: type,
type: 'filters',
category: ComponentCategory.Filter_Price,
supportsCustomTitleForSuggestedScopes: (suggestedScope) => ['bogo'].includes(suggestedScope),
icon: iconWithClassName(({className, context}) => {
if (context === 'card') {
// solid
return
}
// outline
return
}),
fieldsMap: [
[
new RowOptions({
type: 'featured',
colWidth: 'auto'
}),
{id: 'quantity', renderType: FieldType.Number, fieldProps: {type: 'currency', border: false} as NumberProps}
]
]
}
export const ItemPriceRenderer: CardRenderer = {
type,
icon: ItemPriceMeta.icon!,
prefix: '[With] [Specific] *',
AboveComputedValue: usingTestableOptions(({quantity: {type}}, {context}) => {
if ((['tier-base', 'tier-subchild'] as CardRendererContext[]).includes(context)) {
return false
}
switch (type) {
case "equals":
case "range":
return __('Item Price')
case "minimum":
return __('Minimum Item Price')
case "maximum":
return __('Maximum Item Price')
}
}),
ComputedValue: usingTestableOptions(({quantity: {amount, type, range}}, {context}) => {
if (context === 'tier-base') {
return getCardComponentData('filter', type).name
}
switch (type) {
case "equals":
case "minimum":
case "maximum":
return getWithCurrency(amount)
case "range":
return `${getWithCurrency(range.minimum)} - ${getWithCurrency(range.maxmimum)}`
}
}),
}