/** * Product Bundles Configuration * * Types and configuration for the Product Bundles feature */ // Bundle item configuration export interface BundleItem { id: string productId: number productName: string productImage: string productPrice: number variationId?: number variationName?: string discountPercent: number customName?: string hideProductName: boolean hideProductImage: boolean minQuantity: number maxQuantity: number defaultQuantity: number sortOrder: number } // Product Bundle settings export interface ProductBundleSettings { enabled: boolean showStock: boolean showRatings: boolean showOutOfStock: boolean showPriceInCart: boolean showSavingsAmount: boolean productLinkBehavior: 'none' | 'same_tab' | 'new_tab' couponApplication: 'bundle' | 'none' defaultTemplate: 'grid' | 'list' | 'compact' // Pro features allowVariableProducts: boolean // Allow adding variable products to bundles allowOptionalItems: boolean // Allow setting items as required/optional enableItemQuantityLimits: boolean // Enable min/max quantity per item enableRequiredItemsLimit: boolean // Enable min/max required items autoUnavailableOnOutOfStock: boolean // Auto-mark bundle unavailable if item OOS inventorySync: boolean orderPriceDisplay: 'bundle' | 'itemized' // Show bundle or individual prices in orders } // Customization settings export interface BundleCustomization { template: 'grid' | 'list' | 'compact' gridColumns: 1 | 2 | 3 | 4 fontFamily: string backgroundColor: string showItemBorders: boolean borderColor: string borderRadius: number itemSpacing: number showQuantityControls: boolean showStockQuantity: boolean quantityStyle: 'stepper' | 'dropdown' | 'input' quantityAlignment: 'left' | 'center' | 'right' showDiscountBadge: boolean discountBadgePosition: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' discountBadgeColor: string discountBadgeTextColor: string showTotalSavings: boolean savingsPosition: 'above-button' | 'below-button' | 'in-button' savingsColor: string buttonStyle: 'default' | 'full-width' | 'centered' buttonText: string buttonColor: string buttonTextColor: string } // Complete bundle configuration export interface ProductBundle { id: number name: string regularPrice: number salePrice?: number items: BundleItem[] settings: ProductBundleSettings customization: BundleCustomization } // Default settings export const defaultSettings: ProductBundleSettings = { enabled: false, showStock: true, showRatings: true, showOutOfStock: false, showPriceInCart: true, showSavingsAmount: true, productLinkBehavior: 'new_tab', couponApplication: 'bundle', defaultTemplate: 'grid', // Pro features - disabled by default allowVariableProducts: false, allowOptionalItems: false, enableItemQuantityLimits: false, enableRequiredItemsLimit: false, autoUnavailableOnOutOfStock: false, inventorySync: true, orderPriceDisplay: 'bundle', } // Default customization export const defaultCustomization: BundleCustomization = { template: 'grid', gridColumns: 3, fontFamily: '', backgroundColor: '#f9fafb', showItemBorders: true, borderColor: '#e5e7eb', borderRadius: 8, itemSpacing: 16, showQuantityControls: true, showStockQuantity: true, quantityStyle: 'stepper', quantityAlignment: 'left', showDiscountBadge: true, discountBadgePosition: 'top-right', discountBadgeColor: '#ef4444', discountBadgeTextColor: '#ffffff', showTotalSavings: true, savingsPosition: 'above-button', savingsColor: '#16a34a', buttonStyle: 'full-width', buttonText: 'Add Bundle to Cart', buttonColor: '#00226b', buttonTextColor: '#ffffff', } // Template options export const templateOptions = [ { id: 'grid' as const, name: 'Grid Layout', description: 'Products displayed in a grid with images and details', icon: 'grid', }, { id: 'list' as const, name: 'List Layout', description: 'Products displayed in a vertical list with full details', icon: 'list', }, { id: 'compact' as const, name: 'Compact Layout', description: 'Minimalist view with small thumbnails', icon: 'compact', }, ] // Product link options export const productLinkOptions = [ { value: 'none', label: 'No Link', description: 'Product names are not clickable' }, { value: 'same_tab', label: 'Same Tab', description: 'Opens product in the same tab' }, { value: 'new_tab', label: 'New Tab', description: 'Opens product in a new tab' }, ] // Coupon application options export const couponOptions = [ { value: 'bundle', label: 'On Bundle', description: 'Coupons apply to the entire bundle price' }, { value: 'none', label: 'None', description: 'Coupons are disabled for bundles' }, ] // Quantity style options export const quantityStyleOptions = [ { value: 'stepper', label: 'Stepper (+/-)' }, { value: 'dropdown', label: 'Dropdown Select' }, { value: 'input', label: 'Number Input' }, ] // Badge position options export const badgePositionOptions = [ { value: 'top-left', label: 'Top Left' }, { value: 'top-right', label: 'Top Right' }, { value: 'bottom-left', label: 'Bottom Left' }, { value: 'bottom-right', label: 'Bottom Right' }, ] // Savings position options export const savingsPositionOptions = [ { value: 'above-button', label: 'Above Add to Cart' }, { value: 'below-button', label: 'Below Add to Cart' }, { value: 'in-button', label: 'Inside Button' }, ] // Button style options export const buttonStyleOptions = [ { value: 'default', label: 'Default' }, { value: 'full-width', label: 'Full Width' }, { value: 'centered', label: 'Centered' }, ] // Grid column options export const gridColumnOptions = [ { value: 1, label: '1 Column' }, { value: 2, label: '2 Columns' }, { value: 3, label: '3 Columns' }, { value: 4, label: '4 Columns' }, ] // Pre-made style presets export interface StylePreset { id: string name: string description: string preview: string isPro?: boolean alwaysVisible?: boolean customization: Partial } export const stylePresets: StylePreset[] = [ { id: 'classic', name: 'Classic', description: 'Clean and professional look with subtle borders', preview: 'classic', customization: { template: 'grid', gridColumns: 3, backgroundColor: '#f9fafb', showItemBorders: true, borderColor: '#e5e7eb', borderRadius: 8, itemSpacing: 16, showQuantityControls: true, quantityStyle: 'stepper', showDiscountBadge: true, discountBadgePosition: 'top-right', discountBadgeColor: '#ef4444', discountBadgeTextColor: '#ffffff', showTotalSavings: true, savingsPosition: 'above-button', savingsColor: '#16a34a', buttonStyle: 'full-width', buttonColor: '#00226b', buttonTextColor: '#ffffff', }, }, { id: 'minimal', name: 'Minimal', description: 'Simple and elegant with no borders', preview: 'minimal', customization: { template: 'list', gridColumns: 3, backgroundColor: '#ffffff', showItemBorders: false, borderColor: '#e5e7eb', borderRadius: 4, itemSpacing: 12, showQuantityControls: false, quantityStyle: 'input', showDiscountBadge: false, discountBadgePosition: 'top-right', discountBadgeColor: '#ef4444', discountBadgeTextColor: '#ffffff', showTotalSavings: true, savingsPosition: 'below-button', savingsColor: '#059669', buttonStyle: 'centered', buttonColor: '#1f2937', buttonTextColor: '#ffffff', }, }, { id: 'compact-dark', name: 'Compact Dark', description: 'Space-efficient with dark accent colors', preview: 'compact-dark', customization: { template: 'compact', gridColumns: 3, backgroundColor: '#1f2937', showItemBorders: true, borderColor: '#374151', borderRadius: 6, itemSpacing: 8, showQuantityControls: false, quantityStyle: 'stepper', showDiscountBadge: true, discountBadgePosition: 'top-right', discountBadgeColor: '#dc2626', discountBadgeTextColor: '#ffffff', showTotalSavings: true, savingsPosition: 'above-button', savingsColor: '#22c55e', buttonStyle: 'full-width', buttonColor: '#1f2937', buttonTextColor: '#ffffff', }, }, ] // Helper functions export function calculateBundlePrice(items: BundleItem[]): number { return items.reduce((total, item) => { const quantity = item.defaultQuantity || 1 const discount = item.discountPercent || 0 const price = item.productPrice * quantity return total + (price - (price * discount / 100)) }, 0) } export function calculateBundleSavings(items: BundleItem[]): number { const originalTotal = items.reduce((total, item) => { const quantity = item.defaultQuantity || 1 return total + (item.productPrice * quantity) }, 0) const bundlePrice = calculateBundlePrice(items) return originalTotal - bundlePrice } export function formatPrice(price: number, currencySymbol: string = '$'): string { return `${currencySymbol}${price.toFixed(2)}` } export function generateBundleItemId(): string { return `bundle_item_${Date.now()}_${Math.random().toString(36).substr(2, 9)}` }