import {__, CouponsPlus} from "../../../globals" import {ComponentMeta} from "../../ComponentsMeta" import {FieldType} from "../../fields" import {iconWithClassName} from "../../IconWithClassName" import {AmountValidatorOptions} from "../filterinterfaces" import {CardRenderer, CardRendererContext} from "../../CardRenderers"; import {usingTestableOptions} from "../CardHelpers" import {getCardComponentData} from "../../cards" import {ComponentCategory} from "../../components"; import {RowOptions} from "../Fields/RowOptions"; import {NumberProps} from "../../fields/Number"; import React from "react"; export type CouponUsageNumberOfTimesPerUserOptions = AmountValidatorOptions const type = CouponsPlus?.components?.conditions?.CouponUsageNumberOfTimesPerUser?.type || 'CouponUsageNumberOfTimesPerUser' export const CouponUsageNumberOfTimesPerUserMeta: ComponentMeta = { id: type, type: 'conditions', category: ComponentCategory.Coupon, icon: iconWithClassName(({className, context}) => { if (context === 'card') { // solid return } // outline return }), fieldsMap: [ [ new RowOptions({ type: 'featured', colWidth: 'auto', direction: "vertical", gap: 12 }), {id: 'quantity', renderType: FieldType.Number, fieldProps: {border: false, labels: {top: 'Maximum', input: {inputRightOutside: {__('Per user')} }}, showSingleOption: false} as NumberProps}, /*{ id: 'interval', renderType: FieldType.Select, fieldOptions: {optionsKey: '_allowed', centered: true}, fieldProps: {size: 'small', style: 'gray', width: 'auto'} as MultiSelectSearchProps, }*/ ], ] } export const CouponUsageNumberOfTimesPerUserRenderer: CardRenderer = { type, icon: CouponUsageNumberOfTimesPerUserMeta.icon!, prefix: '[Total] *', example: __('1 per user, 3 per user, 10 per user, etc.'), AboveComputedValue: usingTestableOptions(({quantity: {type}}, {context}) => { if ((['tier-base', 'tier-subchild'] as CardRendererContext[]).includes(context)) { return false } return undefined }), ComputedValue: usingTestableOptions(({quantity: {amount}}, {context}) => { if (context === 'tier-base') { return getCardComponentData('condition', type).name } return
{amount} {__('per user')}
; }), }