import {__, CouponsPlus} from "../../../globals" import {ComponentMeta} from "../../ComponentsMeta" import {iconWithClassName} from "../../IconWithClassName" import {CardRenderer, CardRendererContext} from "../../CardRenderers"; import {usingTestableOptions} from "../CardHelpers" import {invert} from "lodash"; import {ComponentCategory} from "../../components"; import {inclusionValueValidatorFieldsMap} from "../InclusionValueValidator"; export type ShippingMethodOptions = { ids: string[], inclusionType: 'allowed' | 'forbidden' } const type = CouponsPlus?.components?.conditions?.ShippingMethod?.type || 'ShippingMethod' export const ShippingMethodMeta: ComponentMeta = { id: type, type: 'conditions', category: ComponentCategory.Checkout, icon: iconWithClassName(({className, context}) => { if (context === 'card') { // solid return } // outline return }), fieldsMap: inclusionValueValidatorFieldsMap('conditions', type, undefined, 'ids', { options: invert(CouponsPlus?.shippingMethods) }) } export const ShippingMethodRenderer: CardRenderer = { type, icon: ShippingMethodMeta.icon!, prefix: '*', example: '', AboveComputedValue: usingTestableOptions(({inclusionType}, {context}) => { if ((['tier-base', 'tier-subchild'] as CardRendererContext[]).includes(context)) { return false } if (inclusionType === 'allowed') { return __('Eligible Shipping Methods') } else { return __('Ineligible Shipping Methods') } }), ComputedValue: usingTestableOptions(({ids}, {context}) => { return {ids.map(methodToFind => { return {CouponsPlus?.shippingMethods[methodToFind] || methodToFind} ; })} ; }), }