import {__, CouponsPlus} from "../../../globals" import {ComponentMeta} from "../../ComponentsMeta" import {FieldType} from "../../fields" import {iconWithClassName} from "../../IconWithClassName" import {AmountValidatorOptions} from "../filterinterfaces" import {NumberProps} from "../../fields/Number"; import {CardRenderer, CardRendererContext} from "../../CardRenderers"; import {usingTestableOptions} from "../CardHelpers" import {getCardComponentData} from "../../cards" import {getWithCurrency} from "../../fields/Currency"; import {ComponentCategory} from "../../components"; import {RowOptions} from "../Fields/RowOptions"; export type TotalSpendOptions = { amount: AmountValidatorOptions } const type = CouponsPlus?.components?.conditions?.TotalSpend?.type || 'TotalSpend' export const TotalSpendMeta: ComponentMeta = { id: type, type: 'conditions', category: ComponentCategory.PurchaseHistory, icon: iconWithClassName(({className, context}) => { if (context === 'card') { // solid return } // outline return }), fieldsMap: [ [ new RowOptions({ type: 'featured', colWidth: 'auto', direction: "vertical", }), {id: 'amount.quantity', renderType: FieldType.Number, fieldProps: {type: 'currency', border: false} as NumberProps} ] ] } export const TotalSpendRenderer: CardRenderer = { type, icon: TotalSpendMeta.icon!, prefix: '*', example: __('$500 or more, $1000 - $2000, etc.'), AboveComputedValue: usingTestableOptions(({amount: {quantity: {type}}}, {context}) => { if ((['tier-base', 'tier-subchild'] as CardRendererContext[]).includes(context)) { return false } /** * This gets repeated across multiple components, should be refactored */ switch (type) { case "equals": case "range": return undefined case "minimum": return __('Minimum Total Spend') case "maximum": return __('Maximum Total Spend') } }), ComputedValue: usingTestableOptions(({amount: {quantity: {amount, type, range}}}, {context}) => { if (context === 'tier-base') { return getCardComponentData('condition', type).name } switch (type) { case "equals": case "minimum": case "maximum": return getWithCurrency(amount) case "range": return `${getWithCurrency(range.minimum)} - ${getWithCurrency(range.maxmimum)}` } }), }