'use client'; import React, { useState, useEffect } from 'react'; import { CreditCard, Zap, Save, Check, ShieldCheck, QrCode } from 'lucide-react'; import { PaymentMethod } from '@/types'; import { INITIAL_PAYMENT_METHODS } from '@/lib/data-service'; import { formatCOP } from '@/lib/pricing-engine'; export default function AdminPaymentMethodsPage() { const [methods, setMethods] = useState(INITIAL_PAYMENT_METHODS); const [message, setMessage] = useState(null); useEffect(() => { fetch('/api/payment-methods') .then((r) => r.json()) .then((d) => d.success && setMethods(d.paymentMethods)) .catch(() => {}); }, []); const handleToggleActive = async (method: PaymentMethod) => { const updated = { ...method, isActive: !method.isActive }; setMethods((prev) => prev.map((m) => (m.id === method.id ? updated : m))); await fetch('/api/payment-methods', { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ id: method.id, updates: { isActive: updated.isActive } }), }); setMessage(`Método "${method.name}" ${updated.isActive ? 'activado' : 'desactivado'}.`); }; const handleUpdateField = (id: string, field: keyof PaymentMethod, val: any) => { setMethods((prev) => prev.map((m) => (m.id === id ? { ...m, [field]: val } : m)) ); }; const handleSaveMethod = async (method: PaymentMethod) => { await fetch('/api/payment-methods', { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ id: method.id, updates: method }), }); setMessage(`✅ Cambios guardados para "${method.name}".`); }; return (
{/* Header */}

Configuración de Medios de Pago & Anticipos

Habilita métodos de pago, configura el valor de separación de $10.000 COP y personaliza los datos de Nequi / Daviplata.

{message && (
{message}
)} {/* Methods Cards */}
{methods.map((method) => (
{method.type === 'contraentrega' ? : }

{method.name}

Tipo: {method.type}
handleUpdateField(method.id, 'name', e.target.value)} className="w-full bg-neutral-900 border border-neutral-800 rounded-xl px-3 py-2 text-xs text-white outline-hidden" />
handleUpdateField(method.id, 'description', e.target.value)} className="w-full bg-neutral-900 border border-neutral-800 rounded-xl px-3 py-2 text-xs text-white outline-hidden" />
{method.requiresDeposit && (
handleUpdateField(method.id, 'depositAmount', parseInt(e.target.value, 10) || 0)} className="w-full bg-neutral-900 border border-neutral-800 rounded-xl px-3 py-2 text-xs text-white outline-hidden font-bold" /> (El saldo restante se cobra contraentrega al recibir)
)}
handleUpdateField(method.id, 'accountInfo', e.target.value)} className="w-full bg-neutral-900 border border-neutral-800 rounded-xl px-3 py-2 text-xs text-white outline-hidden" placeholder="Ej: Nequi / Daviplata: 3XX XXX XXXX" />
))}
); }