/** * Pricing Table Component * Display subscription plans in a table format */ import { useState } from 'react'; import { CheckIcon } from '../../../icons'; import Button from '../button/Button'; export interface PricingPlan { id: number; name: string; monthlyPrice: number; price: number; originalPrice?: number; period: string; description: string; features: string[]; buttonText: string; highlighted?: boolean; disabled?: boolean; annualDiscountPercent?: number; // Plan limits max_sites?: number; max_users?: number; max_keywords?: number; max_ahrefs_queries?: number; included_credits?: number; } interface PricingTableProps { variant?: '1' | '2'; title?: string; plans: PricingPlan[]; showToggle?: boolean; onPlanSelect?: (plan: PricingPlan) => void; } export function PricingTable({ variant = '1', title, plans, showToggle = false, onPlanSelect }: PricingTableProps) { const [billingPeriod, setBillingPeriod] = useState<'monthly' | 'annual'>('monthly'); const getPrice = (plan: PricingPlan) => { if (billingPeriod === 'annual') { const discount = plan.annualDiscountPercent || 20; return (plan.monthlyPrice * 12 * (100 - discount) / 100).toFixed(0); } return plan.monthlyPrice.toFixed(0); }; const getPeriod = () => { return billingPeriod === 'annual' ? '/year' : '/month'; }; return (
{title && (

{title}

)} {showToggle && (
{billingPeriod === 'annual' && ( Save {Math.round(plans[0]?.annualDiscountPercent || 20)}% )}
)}
{plans.map((plan) => (
{plan.highlighted && (
Popular
)}

{plan.name}

{plan.description}

${getPrice(plan)} {getPeriod()} {plan.originalPrice && billingPeriod === 'monthly' && ( ${plan.originalPrice.toFixed(2)} )}
{billingPeriod === 'annual' && plan.monthlyPrice > 0 && (

Billed ${(plan.monthlyPrice * 12 * (100 - (plan.annualDiscountPercent || 20)) / 100).toFixed(0)}/year

)}
    {plan.features.map((feature, index) => (
  • {feature}
  • ))} {/* Plan Limits Section */} {(plan.max_sites || plan.max_keywords || plan.included_credits) && (
    LIMITS
    {plan.max_sites && (
  • {plan.max_sites === 99999 ? 'Unlimited' : plan.max_sites} Sites
  • )} {plan.max_users && (
  • {plan.max_users === 99999 ? 'Unlimited' : plan.max_users} Team Members
  • )} {plan.max_keywords && (
  • {plan.max_keywords.toLocaleString()} Keywords
  • )} {plan.included_credits && (
  • {plan.included_credits.toLocaleString()} Credits/month
  • )}
    )}
))}
); }