import {__, CouponsPlus} from "../../../globals" import {ComponentMeta} from "../../ComponentsMeta" import {iconWithClassName} from "../../IconWithClassName" import {CardRenderer, CardRendererContext} from "../../CardRenderers"; import {usingTestableOptions} from "../CardHelpers" import {ComponentCategory} from "../../components"; import {CustomFieldComputedValue} from "./CustomField"; import {FieldType} from "../../fields"; import {TabFieldProps} from "../../fields/TabField"; import {TabsProps} from "../../fields/tabs"; import {CalendarProps} from "../../fields/Calendar"; import {TimeFieldProps} from "../../fields/TimeField"; import dayjs from "dayjs"; import localizedFormat from "dayjs/plugin/localizedFormat"; dayjs.extend(localizedFormat) export type DateOptions = { 'type' : 'exact' | 'range', 'date' : { 'exact': string, // hour is ignored 'from': string, // hours are considered! 'to': string // hours are considered! }, // only used when type is 'exact', because range already supports hours 'exactHours' : { enabled: 'yes' | 'no', 'from' : string, // hours! 'to' : string // hours! } } const type = CouponsPlus?.components?.conditions?.Date?.type || 'Date' export const DateMeta: ComponentMeta = { id: type, type: 'conditions', category: ComponentCategory.Time, icon: iconWithClassName(({className, context}) => { if (context === 'card') { // solid return } // outline return }), // @ts-ignore fieldsMap: ({options: {type, exactHours}}: {options: DateOptions}) => [ [ {id: 'type', renderType: FieldType.Tab}, ], ...type === 'exact' ? ([ [ {id: 'date.exact', renderType: FieldType.Date} ], [ { id: 'exactHours.enabled', renderType: FieldType.Tab, fieldProps: { size: 'extra-small', dimUnselected: true, width: 'auto' } as TabsProps, fieldOptions: { centered: true } } ], exactHours.enabled === 'yes' && [ { id: 'exactHours.from', renderType: FieldType.Time, wrap: (fieldToRender) =>
{dayjs(source, parseFormat).format('lll')}
>)}