'use client';
import { useState } from 'react';
export function RetryPay({ orderId }: { orderId: string }) {
  const [err, setErr] = useState(''); const [busy, setBusy] = useState(false);
  return (
    <div>
      <button disabled={busy} onClick={async () => {
        setBusy(true); setErr('');
        const r = await fetch(`/api/orders/${orderId}/pay`, { method: 'POST' }); const j = await r.json().catch(() => ({}));
        if (j.redirect) location.href = j.redirect; else { setErr(j.error || 'Ödeme başlatılamadı'); setBusy(false); }
      }} className="btn-signal w-full">{busy ? 'Yönlendiriliyor…' : 'Ödemeyi tamamla'}</button>
      {err && <p className="mt-2 text-sm text-survey-dark">{err}</p>}
    </div>
  );
}
