import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Check, X, ChevronDown, ChevronUp, Sparkles } from 'lucide-react'; import { Card } from '../ui'; import type { PlanMetadata, SubscriptionTier } from '../../api'; type DisplayMode = 'inline' | 'modal'; interface PlanComparisonTableProps { plans: Record; currentTier?: SubscriptionTier; onSelectPlan?: (tier: SubscriptionTier) => void; mode?: DisplayMode; className?: string; } interface FeatureCategory { name: string; features: ComparisonFeature[]; } interface ComparisonFeature { key: string; name: string; description?: string; starterValue: string | boolean; professionalValue: string | boolean; enterpriseValue: string | boolean; highlight?: boolean; // Highlight Professional-exclusive features } export const PlanComparisonTable: React.FC = ({ plans, currentTier, onSelectPlan, mode = 'inline', className = '' }) => { const { t } = useTranslation('subscription'); const [expandedCategories, setExpandedCategories] = useState>(new Set(['limits'])); const toggleCategory = (category: string) => { const newExpanded = new Set(expandedCategories); if (newExpanded.has(category)) { newExpanded.delete(category); } else { newExpanded.add(category); } setExpandedCategories(newExpanded); }; // Define feature categories with comparison data const featureCategories: FeatureCategory[] = [ { name: t('categories.daily_operations'), features: [ { key: 'inventory_management', name: t('features.inventory_management'), starterValue: true, professionalValue: true, enterpriseValue: true }, { key: 'sales_tracking', name: t('features.sales_tracking'), starterValue: true, professionalValue: true, enterpriseValue: true }, { key: 'production_planning', name: t('features.production_planning'), starterValue: true, professionalValue: true, enterpriseValue: true }, { key: 'order_management', name: t('features.order_management'), starterValue: true, professionalValue: true, enterpriseValue: true }, { key: 'supplier_management', name: t('features.supplier_management'), starterValue: true, professionalValue: true, enterpriseValue: true } ] }, { name: t('categories.smart_forecasting'), features: [ { key: 'basic_forecasting', name: t('features.basic_forecasting'), starterValue: '7 days', professionalValue: '90 days', enterpriseValue: '365 days', highlight: true }, { key: 'demand_prediction', name: t('features.demand_prediction'), starterValue: true, professionalValue: true, enterpriseValue: true }, { key: 'seasonal_patterns', name: t('features.seasonal_patterns'), starterValue: false, professionalValue: true, enterpriseValue: true, highlight: true }, { key: 'weather_data_integration', name: t('features.weather_data_integration'), starterValue: false, professionalValue: true, enterpriseValue: true, highlight: true }, { key: 'traffic_data_integration', name: t('features.traffic_data_integration'), starterValue: false, professionalValue: true, enterpriseValue: true, highlight: true }, { key: 'scenario_modeling', name: t('features.scenario_modeling'), starterValue: false, professionalValue: true, enterpriseValue: true, highlight: true }, { key: 'what_if_analysis', name: t('features.what_if_analysis'), starterValue: false, professionalValue: true, enterpriseValue: true, highlight: true } ] }, { name: t('categories.business_insights'), features: [ { key: 'basic_reporting', name: t('features.basic_reporting'), starterValue: true, professionalValue: true, enterpriseValue: true }, { key: 'advanced_analytics', name: t('features.advanced_analytics'), starterValue: false, professionalValue: true, enterpriseValue: true, highlight: true }, { key: 'profitability_analysis', name: t('features.profitability_analysis'), starterValue: false, professionalValue: true, enterpriseValue: true, highlight: true }, { key: 'waste_analysis', name: t('features.waste_analysis'), starterValue: false, professionalValue: true, enterpriseValue: true, highlight: true } ] }, { name: t('categories.multi_location'), features: [ { key: 'multi_location_support', name: t('features.multi_location_support'), starterValue: '1', professionalValue: '3', enterpriseValue: t('limits.unlimited'), highlight: true }, { key: 'location_comparison', name: t('features.location_comparison'), starterValue: false, professionalValue: true, enterpriseValue: true, highlight: true }, { key: 'inventory_transfer', name: t('features.inventory_transfer'), starterValue: false, professionalValue: true, enterpriseValue: true, highlight: true } ] }, { name: t('categories.integrations'), features: [ { key: 'pos_integration', name: t('features.pos_integration'), starterValue: false, professionalValue: true, enterpriseValue: true, highlight: true }, { key: 'accounting_export', name: t('features.accounting_export'), starterValue: false, professionalValue: true, enterpriseValue: true, highlight: true }, { key: 'api_access', name: 'API Access', starterValue: false, professionalValue: 'Basic', enterpriseValue: 'Full', highlight: true }, { key: 'erp_integration', name: t('features.erp_integration'), starterValue: false, professionalValue: false, enterpriseValue: true }, { key: 'sso_saml', name: t('features.sso_saml'), starterValue: false, professionalValue: false, enterpriseValue: true } ] } ]; // Limits comparison const limitsCategory: FeatureCategory = { name: 'Limits & Quotas', features: [ { key: 'users', name: t('limits.users'), starterValue: '5', professionalValue: '20', enterpriseValue: t('limits.unlimited'), highlight: true }, { key: 'locations', name: t('limits.locations'), starterValue: '1', professionalValue: '3', enterpriseValue: t('limits.unlimited'), highlight: true }, { key: 'products', name: t('limits.products'), starterValue: '50', professionalValue: '500', enterpriseValue: t('limits.unlimited'), highlight: true }, { key: 'training_jobs', name: 'Training Jobs/Day', starterValue: '1', professionalValue: '5', enterpriseValue: t('limits.unlimited'), highlight: true }, { key: 'forecasts', name: 'Forecasts/Day', starterValue: '10', professionalValue: '100', enterpriseValue: t('limits.unlimited'), highlight: true }, { key: 'api_calls', name: 'API Calls/Hour', starterValue: '100', professionalValue: '1,000', enterpriseValue: '10,000', highlight: true } ] }; const renderValue = (value: string | boolean, tierKey: string) => { const isProfessional = tierKey === 'professional'; if (typeof value === 'boolean') { return value ? ( ) : ( ); } return ( {value} ); }; const allCategories = [limitsCategory, ...featureCategories]; // Conditional wrapper based on mode const Wrapper = mode === 'inline' ? Card : 'div'; const wrapperProps = mode === 'inline' ? { className: `p-6 overflow-hidden ${className}` } : { className }; return ( {mode === 'inline' && (

{t('ui.compare_plans')}

{t('ui.detailed_feature_comparison')}

)} {/* Add padding-top to prevent Best Value badge from being cut off */}
{/* Header */} {/* Body with collapsible categories */} {allCategories.map((category) => ( {/* Category Header */} toggleCategory(category.name)} > {/* Category Features */} {expandedCategories.has(category.name) && category.features.map((feature, idx) => ( ))} ))}
{t('ui.feature')}
Starter
€49/mo
{t('ui.best_value')}
Professional
€149/mo
Enterprise
€499/mo
{category.name} {expandedCategories.has(category.name) ? ( ) : ( )}
{feature.highlight && ( )} {feature.name}
{renderValue(feature.starterValue, 'starter')} {renderValue(feature.professionalValue, 'professional')} {renderValue(feature.enterpriseValue, 'enterprise')}
{/* Footer with CTA - only show in inline mode */} {mode === 'inline' && onSelectPlan && (
)}
); };