"use client"; import React, { useState } from 'react'; import { X, Plus, Trash2, Save, Loader2 } from 'lucide-react'; import { updatePricingPlanDetail } from '@/app/actions/plans'; import { toast } from 'react-hot-toast'; interface PlanEditModalProps { isOpen: boolean; onClose: () => void; plan: any; currentCycle: 'monthly' | 'yearly'; } export default function PlanEditModal({ isOpen, onClose, plan, currentCycle }: PlanEditModalProps) { const [loading, setLoading] = useState(false); const [formData, setFormData] = useState({ name: plan.name, priceXOF: plan.priceXOF, yearlyPriceXOF: plan.yearlyPriceXOF || '', priceEUR: plan.priceEUR, yearlyPriceEUR: plan.yearlyPriceEUR || '', description: plan.description, offerLimit: plan.offerLimit.toString(), recommended: plan.recommended, color: plan.color, }); const [features, setFeatures] = useState(plan.features || []); const handleAddFeature = () => { setFeatures([...features, '']); }; const handleFeatureChange = (index: number, value: string) => { const newFeatures = [...features]; newFeatures[index] = value; setFeatures(newFeatures); }; const handleRemoveFeature = (index: number) => { setFeatures(features.filter((_, i) => i !== index)); }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); try { const result = await updatePricingPlanDetail(plan.id, { ...formData, features: features.filter(f => f.trim() !== ''), }); if (result.success) { toast.success("Détails du forfait mis à jour !"); onClose(); window.location.reload(); // Refresh to catch changes } else { toast.error(result.error || "Erreur lors de la sauvegarde."); } } catch (error) { toast.error("Erreur réseau"); } finally { setLoading(false); } }; if (!isOpen) return null; return (
{/* Header */}

Modifier le plan {plan.tier}

Édition du mode {currentCycle === 'yearly' ? 'Annuel' : 'Mensuel'}

{/* Content */}
setFormData({...formData, name: e.target.value})} className="w-full bg-slate-950 border border-slate-700 rounded-xl p-3 text-white focus:outline-none focus:border-indigo-500 transition-colors" />
setFormData({...formData, offerLimit: e.target.value})} className="w-full bg-slate-950 border border-slate-700 rounded-xl p-3 text-white focus:outline-none focus:border-indigo-500 transition-colors" />
{currentCycle === 'monthly' ? ( <>
setFormData({...formData, priceXOF: e.target.value})} className="w-full bg-slate-950 border border-slate-700 rounded-xl p-3 text-white focus:outline-none focus:border-indigo-500 transition-colors" />
setFormData({...formData, priceEUR: e.target.value})} className="w-full bg-slate-950 border border-slate-700 rounded-xl p-3 text-white focus:outline-none focus:border-indigo-500 transition-colors" />
) : ( <>
setFormData({...formData, yearlyPriceXOF: e.target.value})} placeholder="ex: 45 000 FCFA" className="w-full bg-slate-950 border border-slate-700 rounded-xl p-3 text-white focus:outline-none focus:border-indigo-500 transition-colors shadow-[0_0_10px_rgba(16,185,129,0.1)] border-emerald-500/30" />
setFormData({...formData, yearlyPriceEUR: e.target.value})} placeholder="ex: 69 €" className="w-full bg-slate-950 border border-slate-700 rounded-xl p-3 text-white focus:outline-none focus:border-indigo-500 transition-colors shadow-[0_0_10px_rgba(16,185,129,0.1)] border-emerald-500/30" />
)}