'use client'; import { useState, useEffect } from 'react'; import { useLanguage } from '@/context/LanguageContext'; import { paymentOptionsApi, PaymentOptionsConfig } from '@/lib/api'; import Card from '@/components/ui/Card'; import Button from '@/components/ui/Button'; import Input from '@/components/ui/Input'; import { CreditCardIcon, BanknotesIcon, BoltIcon, BuildingLibraryIcon, CheckCircleIcon, XCircleIcon, ArrowPathIcon, TicketIcon, Cog6ToothIcon, } from '@heroicons/react/24/outline'; import toast from 'react-hot-toast'; export default function PaymentOptionsPage() { const { t, locale } = useLanguage(); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); const [options, setOptions] = useState({ tpagoEnabled: false, tpagoLink: null, tpagoLink2: null, tpagoLink3: null, tpagoLink4: null, tpagoLink5: null, tpagoInstructions: null, tpagoInstructionsEs: null, bankTransferEnabled: false, bankName: null, bankAccountHolder: null, bankAccountNumber: null, bankAlias: null, bankPhone: null, bankNotes: null, bankNotesEs: null, lightningEnabled: true, cashEnabled: true, cashInstructions: null, cashInstructionsEs: null, allowDuplicateBookings: false, }); useEffect(() => { loadOptions(); }, []); const loadOptions = async () => { try { setLoading(true); const { paymentOptions } = await paymentOptionsApi.getGlobal(); setOptions(paymentOptions); } catch (error) { console.error('Failed to load payment options:', error); toast.error('Failed to load payment options'); } finally { setLoading(false); } }; const handleSave = async () => { try { setSaving(true); await paymentOptionsApi.updateGlobal(options); toast.success('Payment options saved successfully'); } catch (error: any) { toast.error(error.message || 'Failed to save payment options'); } finally { setSaving(false); } }; const updateOption = ( key: K, value: PaymentOptionsConfig[K] ) => { setOptions((prev) => ({ ...prev, [key]: value })); }; if (loading) { return (
); } return (

{locale === 'es' ? 'Opciones de Pago' : 'Payment Options'}

{locale === 'es' ? 'Configura los métodos de pago disponibles para todos los eventos' : 'Configure payment methods available for all events'}

{/* TPago / International Card */}

{locale === 'es' ? 'TPago / Tarjeta Internacional' : 'TPago / International Card'}

{locale === 'es' ? 'Pago manual - requiere aprobación' : 'Manual payment - requires approval'}

{options.tpagoEnabled && (

{locale === 'es' ? 'Cada enlace tiene un monto fijo. Usá un enlace distinto para cada cantidad de tickets.' : 'Each link has a fixed amount. Use a different link for each ticket quantity.'}

{([1, 2, 3, 4, 5] as const).map((qty) => { const key = (qty === 1 ? 'tpagoLink' : `tpagoLink${qty}`) as keyof PaymentOptionsConfig; return (
{qty} {locale === 'es' ? (qty === 1 ? 'ticket' : 'tickets') : (qty === 1 ? 'ticket' : 'tickets')} updateOption(key, (e.target.value || null) as any)} placeholder="https://www.tpago.com.py/links?alias=..." className="flex-1" />
); })}