import {ComponentMeta, ComponentType} from "./ComponentsMeta"; import {__, CouponsPlus} from "../globals"; import {cloneDeep} from "lodash"; export type ComponentRuntimeData = { type: string, options: { [key: string]: any } } export enum ComponentCategory { Default = 'default', Common = 'common', Other = 'other', Account = 'account', PurchaseHistory = 'purchaseHistory', Cart = 'cart', Checkout = 'checkout', Time = 'time', BOGO = 'bogo', Pro = 'pro', Filter_Price = 'filter_price', // specifically for filters, because we might have "price" for conditions and that carries a different context Suggested = 'suggested', Coupon = 'coupon', CartItemDiscounts = 'cart_and_items', } export const componentCategories: Record = { [ComponentCategory.Default]: { label: __('Default'), }, [ComponentCategory.Common]: { label: __('Common'), }, [ComponentCategory.Other]: { label: __('Other'), }, [ComponentCategory.PurchaseHistory]: { label: __('Customer Purchase History'), }, [ComponentCategory.Cart]: { label: __('Cart'), priority: 1 }, [ComponentCategory.Coupon]: { label: __('Coupon'), priority: 2, }, [ComponentCategory.Account]: { label: __('User Account'), priority: 3, }, [ComponentCategory.Checkout]: { label: __('Checkout'), }, [ComponentCategory.Time]: { label: __('Date & Time'), }, [ComponentCategory.BOGO]: { label: __('Buy One, Get One (BOGO)'), priority: 1 }, [ComponentCategory.CartItemDiscounts]: { label: __('Cart & Item Discounts'), priority: 2 }, [ComponentCategory.Pro]: { label: __('Pro'), }, [ComponentCategory.Filter_Price]: { label: __('Price'), }, [ComponentCategory.Suggested]: { label: __(''), }, } export enum ComponentAction { Select, Specify, Add, Exclude, } export type ParentType = { parentType: ComponentType, }; export type ComponentRuntimeDataWithParentType = ParentType & ComponentRuntimeData export const getDefaultRuntimeComponentData = (componentMeta: ComponentMeta): ComponentRuntimeData => { return cloneDeep({ type: componentMeta.id, options: CouponsPlus.components?.[componentMeta.type]?.[componentMeta.id]?.defaultOptions }) } export const getDefaultRuntimeComponentDataWithParentType = (componentMeta: ComponentMeta): ComponentRuntimeDataWithParentType => { return { parentType: componentMeta.type, ...getDefaultRuntimeComponentData(componentMeta) } }