import {__, CouponsPlus} from "../../../globals" import {ComponentMeta} from "../../ComponentsMeta" import {iconWithClassName} from "../../IconWithClassName" import {CardRenderer, CardRendererContext} from "../../CardRenderers"; import {usingTestableOptions} from "../CardHelpers" import {findKey, invert} from "lodash"; import {ComponentCategory} from "../../components"; import {inclusionValueValidatorFieldsMap} from "../InclusionValueValidator"; export type PaymentMethodOptions = { ids: string[], inclusionType: 'allowed' | 'forbidden' } const type = CouponsPlus?.components?.conditions?.PaymentMethod?.type || 'PaymentMethod' export const PaymentMethodMeta: 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?.paymentMethods) }) } export const PaymentMethodRenderer: CardRenderer = { type, icon: PaymentMethodMeta.icon!, prefix: '*', example: __('Direct Bank Transfer, PayPal Payments, etc.'), AboveComputedValue: usingTestableOptions(({inclusionType}, {context}) => { if ((['tier-base', 'tier-subchild'] as CardRendererContext[]).includes(context)) { return false } if (inclusionType === 'allowed') { return __('Eligible Payment Methods') } else { return __('Ineligible Payment Methods') } }), ComputedValue: usingTestableOptions(({ids}, {context}) => { return
{ids.map(methodToFind => { return
{CouponsPlus?.paymentMethods[methodToFind] || methodToFind}
; })}
; }), }