'use client' import { useEffect, useState } from 'react' import Link from 'next/link' import { useMarketplacePreferences } from '@/components/MarketplaceShell' import { resolveBrowserAppUrl } from '@/lib/appUrls' type Currency = 'MAD' | 'USD' | 'EUR' type Billing = 'monthly' | 'annual' const SYMBOL: Record = { MAD: 'MAD', USD: '$', EUR: '€' } const LANGUAGE_CURRENCY: Record = { ar: 'MAD', fr: 'EUR', en: 'USD' } const PRICES: Record> = { STARTER: { MAD: { monthly: 299, annual: 299 }, USD: { monthly: 29, annual: 290 }, EUR: { monthly: 27, annual: 270 }, }, GROWTH: { MAD: { monthly: 599, annual: 399 }, USD: { monthly: 59, annual: 590 }, EUR: { monthly: 55, annual: 550 }, }, PRO: { MAD: { monthly: 999, annual: 9990 }, USD: { monthly: 99, annual: 990 }, EUR: { monthly: 92, annual: 920 }, }, } 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 fmt(value: number, currency: Currency, billing: Billing): string { const sym = SYMBOL[currency] const amount = billing === 'annual' ? Math.round(value / 12) : value return currency === 'MAD' ? `${amount} ${sym}` : `${sym}${amount}` } function annualSavingsPct(plan: string, currency: Currency): number { const { monthly, annual } = PRICES[plan][currency] const wouldPay = monthly * 12 return Math.round(((wouldPay - annual) / wouldPay) * 100) } export default function PricingClient() { const { language } = useMarketplacePreferences() const dict = copy[language] const [currency, setCurrency] = useState(() => LANGUAGE_CURRENCY[language] ?? 'MAD') const [billing, setBilling] = useState('monthly') useEffect(() => { setCurrency(LANGUAGE_CURRENCY[language] ?? 'MAD') }, [language]) const dashboardUrl = resolveBrowserAppUrl(process.env.NEXT_PUBLIC_DASHBOARD_URL ?? 'http://localhost:3000/dashboard') const savings = annualSavingsPct('STARTER', currency) return (
{/* Toggles */}
{/* Billing toggle */}
{(['monthly', 'annual'] as Billing[]).map((b) => ( ))}
{/* Currency toggle */}
{(['MAD', 'USD', 'EUR'] as Currency[]).map((c) => ( ))}
{billing === 'annual' && (

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

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

{plan.name}

{plan.tagline}

{currency === 'MAD' ? displayPrice : `${sym}${displayPrice}`} {currency === 'MAD' && ( {sym} )} {dict.perMonth}
{billing === 'annual' && (

{dict.billedAs}{' '} {currency === 'MAD' ? `${price.annual} ${sym}` : `${sym}${price.annual}`}{' '} {dict.yearly}

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

{dict.footer}

) }