import React from 'react';

const history = [
  { date: '2026-05-07', account: '10+3 Bonuskarte', type: 'consume', gas: 'Nitrox 32', value: '-2', balance: '6', actor: 'Kunde + Anna', status: 'gebucht', tone: 'green' },
  { date: '2026-05-03', account: '10+3 Bonuskarte', type: 'consume', gas: 'Luft', value: '-1', balance: '8', actor: 'Mitarbeiter', status: 'gebucht', tone: 'green' },
  { date: '2026-05-01', account: '10+3 Bonuskarte', type: 'topup + bonus', gas: 'Luft', value: '+13', balance: '13', actor: 'Anna', status: 'Anlage', tone: 'blue' },
  { date: '2026-04-28', account: 'Punktekarte', type: 'correction', gas: '-', value: '+1', balance: '14', actor: 'tenant_admin', status: 'korrigiert', tone: 'yellow' },
  { date: '2026-04-20', account: '10er-Karte', type: 'reverse', gas: 'Luft', value: '+1', balance: '5', actor: 'Anna', status: 'Storno', tone: 'red' },
];

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 Metric({ label, value, tone = 'gray' }) {
  return (
    <div className="rounded-2xl border border-slate-200 bg-white p-4 shadow-sm">
      <p className="text-xs font-semibold uppercase tracking-wide text-slate-500">{label}</p>
      <p className="mt-2 text-2xl font-bold text-slate-900">{value}</p>
      <div className="mt-2"><Badge tone={tone}>{label}</Badge></div>
    </div>
  );
}

export default function FA08FuellhistorieJeKunde() {
  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-08</p>
              <h1 className="mt-1 text-3xl font-bold">Füllhistorie je Kunde</h1>
              <p className="mt-2 max-w-3xl text-sm text-slate-600">
                Maria Keller · Historie über alle Füllkarten, Abos, Buchungen, Stornos und Self-Service-Abrufe.
              </p>
            </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">Kundenprofil</button>
              <button className="rounded-xl border border-slate-300 bg-white px-4 py-2 text-sm font-semibold text-slate-800">Export</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="grid gap-4 md:grid-cols-2 xl:grid-cols-5">
          <Metric label="aktive Konten" value="2" tone="green" />
          <Metric label="Rest gesamt" value="11" tone="blue" />
          <Metric label="offene Abrufe" value="1" tone="yellow" />
          <Metric label="Konflikte" value="0" tone="green" />
          <Metric label="Korrekturen" value="2" tone="yellow" />
        </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">
            {['letzte 30 Tage', 'alle Konten', 'alle Vorgänge', 'Gasart', 'Status'].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">Historie</h2>
              <p className="text-sm text-slate-500">Lesende Ansicht. Korrektur oder Storno erfolgt nur über FA-10.</p>
            </div>
            <Badge tone="gray">{history.length} Einträge</Badge>
          </div>
          <div className="overflow-x-auto">
            <table className="w-full min-w-[1100px] 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">Füllkonto</th>
                  <th className="px-5 py-3">Vorgang</th>
                  <th className="px-5 py-3">Gas</th>
                  <th className="px-5 py-3">Wert</th>
                  <th className="px-5 py-3">Saldo</th>
                  <th className="px-5 py-3">Auslöser</th>
                  <th className="px-5 py-3">Status</th>
                  <th className="px-5 py-3">Aktion</th>
                </tr>
              </thead>
              <tbody className="divide-y divide-slate-100">
                {history.map((entry) => (
                  <tr key={`${entry.date}-${entry.type}-${entry.value}`} 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.account}</td>
                    <td className="px-5 py-4">{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 font-semibold">{entry.balance}</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">
                      <div className="flex gap-2">
                        <button className="rounded-lg border border-slate-300 px-3 py-1 text-xs font-semibold text-slate-700">Detail</button>
                        <button className="rounded-lg border border-slate-300 px-3 py-1 text-xs font-semibold text-slate-700">Konto</button>
                      </div>
                    </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: Historie verändert keine Ledger-Einträge direkt. Storno und Korrektur benötigen Pflichtgrund, Datum/Zeit und User-Stempel.
          </p>
        </section>
      </div>
    </div>
  );
}
