"use client"; import React, { useState, useEffect } from 'react'; import { Check, X, Smartphone, CreditCard, Loader, ShieldCheck } from 'lucide-react'; interface Plan { id: string; tier: string; name: string; priceXOF: string; yearlyPriceXOF?: string; priceEUR: string; yearlyPriceEUR?: string; description: string; features: string[]; recommended: boolean; color: string; offerLimit: number; } const PricingSection = () => { const [plans, setPlans] = useState([]); const [loadingPlans, setLoadingPlans] = useState(true); const [selectedPlan, setSelectedPlan] = useState(null); const [billingCycle, setBillingCycle] = useState<'monthly' | 'yearly'>('monthly'); const [isPaymentModalOpen, setIsPaymentModalOpen] = useState(false); useEffect(() => { const fetchPlans = async () => { try { const res = await fetch('/api/plans'); const data = await res.json(); if (!data.error) { setPlans(data); } } catch (error) { console.error('Error fetching plans:', error); } finally { setLoadingPlans(false); } }; fetchPlans(); }, []); // Payment State const [paymentStep, setPaymentStep] = useState<'method' | 'processing' | 'success'>('method'); const [paymentMethod, setPaymentMethod] = useState<'mobile_money' | 'card' | null>(null); const handleSelectPlan = (plan: Plan) => { if (plan.tier === 'STARTER') return; // Free plan, no payment setSelectedPlan(plan); setPaymentStep('method'); setIsPaymentModalOpen(true); }; const handlePayment = () => { setPaymentStep('processing'); // Fake API delay setTimeout(() => { setPaymentStep('success'); }, 2500); }; const closePayment = () => { setIsPaymentModalOpen(false); setPaymentStep('method'); setSelectedPlan(null); setPaymentMethod(null); }; return (

Tarifs

Investissez dans votre croissance

Choisissez le plan adapté à vos ambitions. Changez ou annulez à tout moment.

{/* Billing Toggle */}
{/* Plans Grid */}
{loadingPlans ? ( [1, 2, 3].map((i) => (
)) ) : ( plans.map((plan) => (
{plan.recommended && (
Populaire
)}

{plan.name}

{plan.description}

{plan.priceXOF === 'Gratuit' ? 'Gratuit' : (billingCycle === 'yearly' ? (plan.yearlyPriceXOF || plan.priceXOF) : plan.priceXOF ) } {plan.priceXOF !== 'Gratuit' && ( {billingCycle === 'yearly' ? '/an' : '/mois'} )}
{plan.priceXOF !== 'Gratuit' && (

soit env. {billingCycle === 'yearly' ? (plan.yearlyPriceEUR || plan.priceEUR) : plan.priceEUR} {billingCycle === 'yearly' ? '/an' : '/mois'}

)}
    {plan.features.map((feature) => (
  • {feature}

  • ))}
)) )}
{/* FAKE PAYMENT MODAL */} {isPaymentModalOpen && selectedPlan && (
{/* Overlay */}
{/* Header */}
{/* Content based on step */} {paymentStep === 'method' && ( <>

Vous avez choisi le plan {selectedPlan.name} ({billingCycle === 'yearly' ? 'Annuel' : 'Mensuel'})

{billingCycle === 'yearly' ? (selectedPlan.yearlyPriceXOF || selectedPlan.priceXOF) : selectedPlan.priceXOF}

Moyen de paiement

{paymentMethod === 'mobile_money' && (
)} {paymentMethod === 'card' && (
)} )} {paymentStep === 'processing' && (

Traitement en cours...

Veuillez valider la transaction sur votre mobile si nécessaire.

)} {paymentStep === 'success' && (

Paiement Réussi !

Votre abonnement {selectedPlan.name} est maintenant actif.

)}
{paymentStep === 'method' && (
)}
)}
); }; export default PricingSection;