'use client' import { useEffect, useState } from 'react' import Link from 'next/link' import { useMarketplacePreferences } from '@/components/MarketplaceShell' import { resolveBrowserAppUrl } from '@/lib/appUrls' type Billing = 'monthly' | 'annual' const PRICES: Record = { STARTER: { monthly: 299, annual: 2990 }, GROWTH: { monthly: 399, annual: 3990 }, PRO: { monthly: 499, annual: 4990 }, } const PLANS = [ { key: 'STARTER', name: 'Starter', tagline: 'Launch your fleet online', features: [ 'Up to 10 vehicles', '1 user account', 'Basic analytics', 'Marketplace listing', ], highlight: false, }, { key: 'GROWTH', name: 'Growth', tagline: 'Scale with confidence', features: [ 'Up to 50 vehicles', '5 user accounts', 'Full analytics', 'Priority marketplace placement', 'Custom branding', ], highlight: true, }, { key: 'PRO', name: 'Pro', tagline: 'Enterprise-grade power', features: [ 'Unlimited vehicles', 'Unlimited user accounts', 'Advanced reports', 'API access', 'Dedicated support', ], highlight: false, }, ] const copy = { en: { monthly: 'Monthly', annual: 'Annual', yearly: '/ year', youSave: 'You save', withAnnual: 'with annual billing — billed as one payment per year.', mostPopular: 'Most popular', perMonth: '/mo', billedAs: 'Billed as', getStarted: 'Get started', footer: 'All plans include a 90-day free trial. No credit card required.', }, fr: { monthly: 'Mensuel', annual: 'Annuel', yearly: '/ an', youSave: 'Vous économisez', withAnnual: 'avec la facturation annuelle, prélevée en un seul paiement par an.', mostPopular: 'Le plus populaire', perMonth: '/mois', billedAs: 'Facturé à', getStarted: 'Commencer', footer: "Toutes les formules incluent un essai gratuit de 90 jours. Aucune carte bancaire n'est requise.", }, ar: { monthly: 'شهري', annual: 'سنوي', yearly: '/ سنة', youSave: 'توفر', withAnnual: 'مع الفوترة السنوية، تُسدد دفعة واحدة كل سنة.', mostPopular: 'الأكثر شيوعاً', perMonth: '/شهر', billedAs: 'يتم الفوترة بمبلغ', getStarted: 'ابدأ الآن', footer: 'تشمل جميع الخطط تجربة مجانية لمدة 14 يوماً. لا حاجة إلى بطاقة ائتمان.', }, } as const function annualSavingsPct(plan: string): number { const { monthly, annual } = PRICES[plan] const wouldPay = monthly * 12 return Math.round(((wouldPay - annual) / wouldPay) * 100) } export default function PricingClient() { const { language } = useMarketplacePreferences() const dict = copy[language] const [billing, setBilling] = useState('monthly') const dashboardUrl = resolveBrowserAppUrl(process.env.NEXT_PUBLIC_DASHBOARD_URL ?? 'http://localhost:3000/dashboard') const savings = annualSavingsPct('STARTER') return (
{/* Billing toggle */}
{(['monthly', 'annual'] as Billing[]).map((b) => ( ))}
{billing === 'annual' && (

{dict.youSave} {savings}% {dict.withAnnual}

)} {/* Plan cards */}
{PLANS.map((plan) => { const price = PRICES[plan.key] const displayPrice = billing === 'annual' ? Math.round(price.annual / 12) : price.monthly return (
{plan.highlight && (
{dict.mostPopular}
)}

{plan.name}

{plan.tagline}

{displayPrice} MAD {dict.perMonth}
{billing === 'annual' && (

{dict.billedAs} {price.annual} MAD {dict.yearly}

)}
    {plan.features.map((f) => (
  • {f}
  • ))}
{dict.getStarted}
) })}
{/* Footer note */}

{dict.footer}

) }