'use client' import { useState } from 'react' import { useTranslations } from 'next-intl' import type { BattlepayOrder } from '@/lib/battlepay' export function BattlepayList({ orders }: { orders: BattlepayOrder[] }) { const t = useTranslations('Battlepay') const [busy, setBusy] = useState(null) const [error, setError] = useState(null) async function pay(reference: string) { if (busy) return setBusy(reference) setError(null) try { const res = await fetch('/api/battlepay/pay', { method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'same-origin', body: JSON.stringify({ reference }), }) const d: { success?: boolean; url?: string; error?: string } = await res.json() if (d.success && d.url) { window.location.href = d.url } else { setError(t(d.error === 'orderNotFound' ? 'orderNotFound' : 'genericError')) setBusy(null) } } catch { setError(t('genericError')) setBusy(null) } } if (orders.length === 0) return

{t('noOrders')}

return (
{error && {error}}
{orders.map((o) => ( ))}
{o.product_name}
{t('reference')}: {o.reference} {o.created_at ? ` · ${new Date(o.created_at * 1000).toLocaleDateString()}` : ''}
{o.price_eur.toFixed(2)} €
) }