import React from 'react';

const ledger = [
  { date: '2026-05-07', type: 'consume', gas: 'Nitrox 32', value: '-2', before: '10', after: '8', actor: 'Kunde + Anna', status: 'gebucht', tone: 'green', note: 'Analyse vorhanden' },
  { date: '2026-05-03', type: 'consume', gas: 'Luft', value: '-1', before: '11', after: '10', actor: 'Mitarbeiter', status: 'gebucht', tone: 'green', note: '-' },
  { date: '2026-05-02', type: 'correction', gas: '-', value: '+1', before: '10', after: '11', actor: 'tenant_admin', status: 'korrigiert', tone: 'yellow', note: 'Bezug #4711' },
  { date: '2026-05-01', type: 'topup', gas: 'Luft', value: '+10', before: '0', after: '10', actor: 'Anna', status: 'Anlage', tone: 'blue', note: 'bezahlt' },
  { date: '2026-05-01', type: 'bonus', gas: 'Luft', value: '+3', before: '10', after: '13', actor: 'System', status: 'Bonus', tone: 'blue', note: '10+3 Modell' },
];

function Badge({ children, tone = 'gray' }) {
  const tones = {
    green: 'bg-green-100 text-green-800 border-green-200',
    blue: 'bg-blue-100 text-blue-800 border-blue-200',
    yellow: 'bg-yellow-100 text-yellow-800 border-yellow-200',
    red: 'bg-red-100 text-red-800 border-red-200',
    gray: 'bg-slate-100 text-slate-700 border-slate-200',
  };
  return <span className={`inline-flex rounded-full border px-3 py-1 text-xs font-semibold ${tones[tone]}`}>{children}</span>;
}

function Summary({ label, value }) {
  return (
    <div className="rounded-xl border border-slate-200 bg-slate-50 p-4">
      <p className="text-xs font-semibold uppercase tracking-wide text-slate-500">{label}</p>
      <p className="mt-1 text-2xl font-bold text-slate-900">{value}</p>
    </div>
  );
}

export default function FA09FuellhistorieJeFuellkonto() {
  return (
    <div className="min-h-screen bg-slate-50 p-6 text-slate-900">
      <div className="mx-auto max-w-7xl space-y-5">
        <header className="rounded-2xl border border-sky-200 bg-sky-50 p-6 shadow-sm">
          <div className="flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between">
            <div>
              <p className="text-sm font-semibold uppercase tracking-wide text-sky-700">UC03 · FA-09</p>
              <h1 className="mt-1 text-3xl font-bold">Füllhistorie je Füllkonto</h1>
              <p className="mt-2 max-w-3xl text-sm text-slate-600">
                10+3 Bonuskarte Luft · Maria Keller · vollständiger Ledger-Verlauf dieses Füllkontos.
              </p>
              <div className="mt-3 flex flex-wrap gap-2">
                <Badge tone="green">aktiv</Badge>
                <Badge tone="blue">digitale Karte</Badge>
                <Badge tone="green">kein Konflikt</Badge>
              </div>
            </div>
            <div className="flex flex-wrap gap-2">
              <button className="rounded-xl border border-slate-300 bg-white px-4 py-2 text-sm font-semibold text-slate-800">FA-03</button>
              <button className="rounded-xl border border-slate-300 bg-white px-4 py-2 text-sm font-semibold text-slate-800">FA-08</button>
              <button className="rounded-xl bg-sky-700 px-4 py-2 text-sm font-semibold text-white">Füllung buchen</button>
            </div>
          </div>
        </header>

        <section className="rounded-2xl border border-slate-200 bg-white p-5 shadow-sm">
          <div className="grid gap-4 md:grid-cols-3 xl:grid-cols-6">
            <Summary label="bezahlt" value="10" />
            <Summary label="Bonus" value="3" />
            <Summary label="Start" value="13" />
            <Summary label="verbraucht" value="7" />
            <Summary label="Korrektur" value="+2" />
            <Summary label="Rest" value="8 / 13" />
          </div>
          <div className="mt-5 h-3 overflow-hidden rounded-full bg-slate-200">
            <div className="h-full rounded-full bg-sky-600" style={{ width: '62%' }} />
          </div>
        </section>

        <section className="rounded-2xl border border-slate-200 bg-white p-5 shadow-sm">
          <h2 className="text-lg font-bold">Filter</h2>
          <div className="mt-4 grid gap-3 lg:grid-cols-6">
            {['gesamte Laufzeit', 'alle Typen', 'Gasart', 'Status', 'Auslöser'].map((label) => (
              <div key={label} className="rounded-xl border border-slate-300 bg-slate-50 px-3 py-2 text-sm font-semibold text-slate-700">
                {label}
              </div>
            ))}
            <button className="rounded-xl bg-slate-900 px-3 py-2 text-sm font-semibold text-white">Filtern</button>
          </div>
        </section>

        <section className="overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-sm">
          <div className="flex items-center justify-between border-b border-slate-200 px-5 py-4">
            <div>
              <h2 className="text-lg font-bold">Ledger-Verlauf</h2>
              <p className="text-sm text-slate-500">Lesende Ansicht. Reverse- und Correction-Einträge verweisen auf ihre Ursprungsbuchung.</p>
            </div>
            <Badge tone="gray">{ledger.length} Einträge</Badge>
          </div>
          <div className="overflow-x-auto">
            <table className="w-full min-w-[1180px] border-collapse text-left text-sm">
              <thead className="bg-slate-100 text-xs uppercase tracking-wide text-slate-600">
                <tr>
                  <th className="px-5 py-3">Datum</th>
                  <th className="px-5 py-3">Typ</th>
                  <th className="px-5 py-3">Gas</th>
                  <th className="px-5 py-3">Wert</th>
                  <th className="px-5 py-3">vorher</th>
                  <th className="px-5 py-3">nachher</th>
                  <th className="px-5 py-3">Auslöser</th>
                  <th className="px-5 py-3">Status</th>
                  <th className="px-5 py-3">Bezug / Hinweis</th>
                  <th className="px-5 py-3">Aktion</th>
                </tr>
              </thead>
              <tbody className="divide-y divide-slate-100">
                {ledger.map((entry) => (
                  <tr key={`${entry.date}-${entry.type}-${entry.value}-${entry.after}`} className="hover:bg-slate-50">
                    <td className="px-5 py-4 text-slate-600">{entry.date}</td>
                    <td className="px-5 py-4 font-semibold">{entry.type}</td>
                    <td className="px-5 py-4">{entry.gas}</td>
                    <td className="px-5 py-4 font-semibold">{entry.value}</td>
                    <td className="px-5 py-4">{entry.before}</td>
                    <td className="px-5 py-4 font-semibold">{entry.after}</td>
                    <td className="px-5 py-4 text-slate-600">{entry.actor}</td>
                    <td className="px-5 py-4"><Badge tone={entry.tone}>{entry.status}</Badge></td>
                    <td className="px-5 py-4 text-slate-600">{entry.note}</td>
                    <td className="px-5 py-4">
                      <button className="rounded-lg border border-slate-300 px-3 py-1 text-xs font-semibold text-slate-700">Detail</button>
                    </td>
                  </tr>
                ))}
              </tbody>
            </table>
          </div>
        </section>

        <section className="rounded-2xl border border-slate-200 bg-white p-5 shadow-sm">
          <p className="text-sm text-slate-600">
            Hinweis: FA-09 verändert keine Ledger-Einträge. Korrektur oder Storno erfolgt ausschliesslich über FA-10 mit Pflichtgrund und Auditdaten.
          </p>
        </section>
      </div>
    </div>
  );
}
