"use client"; import React, { useState, useEffect } from 'react'; import { Zap, Calendar, Newspaper, Layout, Check, Smartphone, CreditCard, Loader, ShieldCheck, X } from 'lucide-react'; import { useUser } from './UserProvider'; import { useRouter } from 'next/navigation'; import CreateEventModal from './dashboard/CreateEventModal'; import CreateNewsModal from './dashboard/CreateNewsModal'; import { toast } from 'react-hot-toast'; interface OneShotPlan { id: string; type: string; name: string; priceXOF: number; priceEUR: number; description: string | null; } const TYPE_ICONS = { BUMP: Zap, POST_EVENT: Calendar, POST_NEWS: Newspaper, AD_DIRECTORY: Layout, }; const OneShotPricingSection = () => { const [plans, setPlans] = useState([]); const [loading, setLoading] = useState(true); const [selectedPlan, setSelectedPlan] = useState(null); const [isPaymentModalOpen, setIsPaymentModalOpen] = useState(false); const [paymentStep, setPaymentStep] = useState<'method' | 'processing' | 'success'>('method'); const [paymentMethod, setPaymentMethod] = useState<'mobile_money' | 'card' | null>(null); const [showEventModal, setShowEventModal] = useState(false); const [showNewsModal, setShowNewsModal] = useState(false); const { user } = useUser(); const router = useRouter(); useEffect(() => { const fetchPlans = async () => { try { const res = await fetch('/api/one-shot-plans'); const data = await res.json(); if (!data.error) { setPlans(data); } } catch (error) { console.error('Error fetching one-shot plans:', error); } finally { setLoading(false); } }; fetchPlans(); }, []); const handleSelectPlan = (plan: OneShotPlan) => { if (!user) { toast.error("Veuillez vous connecter pour commander un service"); router.push('/login?callback=/subscription'); return; } setSelectedPlan(plan); setPaymentStep('method'); setIsPaymentModalOpen(true); }; const handlePayment = () => { setPaymentStep('processing'); setTimeout(() => { setPaymentStep('success'); }, 2500); }; const closePayment = () => { setIsPaymentModalOpen(false); setPaymentStep('method'); setSelectedPlan(null); setPaymentMethod(null); }; if (!loading && plans.length === 0) return null; return (

Services à la carte

Boostez votre visibilité ponctuellement

Des options flexibles pour mettre en avant vos actualités et vos offres sans engagement.

{loading ? ( [1, 2, 3, 4].map((i) => (
)) ) : ( plans.map((plan) => { const Icon = TYPE_ICONS[plan.type as keyof typeof TYPE_ICONS] || Zap; return (

{plan.name}

{plan.description}

{plan.priceXOF.toLocaleString()} F CFA

env. {plan.priceEUR} €

); }) )}
{/* PAYMENT MODAL (Simplified copy from PricingSection) */} {isPaymentModalOpen && selectedPlan && (

Paiement Service Ponctuel

{paymentStep === 'method' && ( <>

Option : {selectedPlan.name}

{selectedPlan.priceXOF.toLocaleString()} F CFA

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

Sécurisation du paiement...

N'interrompez pas la transaction.

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

Paiement Réussi !

{selectedPlan.type === 'POST_EVENT' || selectedPlan.type === 'POST_NEWS' ? "Votre paiement a été validé. Vous pouvez maintenant remplir le formulaire de votre publication." : `Votre service ${selectedPlan.name} a été activé avec succès.` }

{selectedPlan.type === 'POST_EVENT' || selectedPlan.type === 'POST_NEWS' ? ( ) : ( )}
)}
)} {/* EVENT FORM MODAL */} { setShowEventModal(false); closePayment(); }} /> {/* NEWS FORM MODAL */} { setShowNewsModal(false); closePayment(); }} />
); }; export default OneShotPricingSection;