import React from 'react';

const accounts = [
  {
    customer: 'Maria Keller',
    model: '10+3 Bonuskarte',
    gas: 'Luft',
    balance: '8 / 13',
    status: 'aktiv',
    selfService: 'Bestätigung nötig',
    lastBooking: '2026-05-07',
    actions: ['Öffnen', 'Buchen'],
    statusTone: 'green',
    selfTone: 'blue',
  },
  {
    customer: 'Luca Meier',
    model: '10er-Karte',
    gas: 'Nitrox 32',
    balance: '3 / 10',
    status: 'aktiv',
    selfService: 'aktiv',
    lastBooking: '2026-05-06',
    actions: ['QR', 'Historie'],
    statusTone: 'green',
    selfTone: 'green',
  },
  {
    customer: 'Nina Graf',
    model: 'Punktekarte',
    gas: 'gemischt',
    balance: '14 Punkte',
    status: 'pending_sync',
    selfService: 'Bestätigung nötig',
    lastBooking: 'offline offen',
    actions: ['Prüfen'],
    statusTone: 'yellow',
    selfTone: 'blue',
  },
  {
    customer: 'Tom Berger',
    model: 'Saisonabo',
    gas: 'Luft',
    balance: '0 / 30',
    status: 'leer',
    selfService: 'inaktiv',
    lastBooking: '2026-05-01',
    actions: ['Öffnen'],
    statusTone: 'red',
    selfTone: 'yellow',
  },
];

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 items-center rounded-full border px-3 py-1 text-xs font-medium ${tones[tone]}`}>
      {children}
    </span>
  );
}

export default function FA01FuellkartenUndAbosUebersicht() {
  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-01</p>
              <h1 className="mt-1 text-3xl font-bold">Füllkarten & Abos</h1>
              <p className="mt-2 max-w-3xl text-sm text-slate-600">
                Zentrale Übersicht für aktive Karten, Abos, Guthaben, Status und Self-Service-Abrufe.
              </p>
            </div>
            <div className="flex flex-wrap gap-2">
              <button className="rounded-xl bg-sky-700 px-4 py-2 text-sm font-semibold text-white shadow-sm">Neues Füllkonto</button>
              <button className="rounded-xl bg-sky-700 px-4 py-2 text-sm font-semibold text-white shadow-sm">Füllung erfassen</button>
              <button className="rounded-xl border border-slate-300 bg-white px-4 py-2 text-sm font-semibold text-slate-800 shadow-sm">Offene Abrufe</button>
            </div>
          </div>
        </header>

        <section className="grid gap-3 md:grid-cols-3">
          <div className="rounded-2xl border border-yellow-200 bg-yellow-50 p-4 shadow-sm">
            <p className="text-sm font-semibold text-yellow-900">3 offene Kundenabrufe</p>
            <p className="mt-1 text-xs text-yellow-800">Warten auf Mitarbeiterbestätigung.</p>
          </div>
          <div className="rounded-2xl border border-yellow-200 bg-yellow-50 p-4 shadow-sm">
            <p className="text-sm font-semibold text-yellow-900">2 pending_sync</p>
            <p className="mt-1 text-xs text-yellow-800">Nicht synchronisierte Offline-Buchungen vorhanden.</p>
          </div>
          <div className="rounded-2xl border border-red-200 bg-red-50 p-4 shadow-sm">
            <p className="text-sm font-semibold text-red-900">1 Konflikt</p>
            <p className="mt-1 text-xs text-red-800">Konflikt muss geprüft werden.</p>
          </div>
        </section>

        <section className="rounded-2xl border border-slate-200 bg-white p-5 shadow-sm">
          <h2 className="text-lg font-bold">Filter & Suche</h2>
          <div className="mt-4 grid gap-3 lg:grid-cols-6">
            <div className="lg:col-span-2">
              <label className="text-xs font-semibold text-slate-500">Suche</label>
              <div className="mt-1 rounded-xl border border-slate-300 bg-slate-50 px-3 py-2 text-sm text-slate-500">
                Kunde, Karte, Abo, QR-Code ...
              </div>
            </div>
            {['Status', 'Modell', 'Gasart', 'Self-Service'].map((label) => (
              <div key={label}>
                <label className="text-xs font-semibold text-slate-500">{label}</label>
                <div className="mt-1 rounded-xl border border-slate-300 bg-slate-50 px-3 py-2 text-sm text-slate-700">Alle</div>
              </div>
            ))}
            <div className="flex items-end">
              <button className="w-full rounded-xl bg-slate-900 px-3 py-2 text-sm font-semibold text-white">Filtern</button>
            </div>
          </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">Aktive Füllkarten & Abos</h2>
              <p className="text-sm text-slate-500">Standardansicht zeigt aktive Füllkonten. Abgelaufene oder leere Einträge sind über Filter erreichbar.</p>
            </div>
            <Badge tone="gray">4 Einträge</Badge>
          </div>

          <div className="overflow-x-auto">
            <table className="w-full min-w-[980px] 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">Kunde</th>
                  <th className="px-5 py-3">Modell</th>
                  <th className="px-5 py-3">Gasbereich</th>
                  <th className="px-5 py-3">Rest</th>
                  <th className="px-5 py-3">Status</th>
                  <th className="px-5 py-3">Self-Service</th>
                  <th className="px-5 py-3">Letzte Buchung</th>
                  <th className="px-5 py-3">Aktionen</th>
                </tr>
              </thead>
              <tbody className="divide-y divide-slate-100">
                {accounts.map((account) => (
                  <tr key={`${account.customer}-${account.model}`} className="hover:bg-slate-50">
                    <td className="px-5 py-4 font-semibold">{account.customer}</td>
                    <td className="px-5 py-4">{account.model}</td>
                    <td className="px-5 py-4">{account.gas}</td>
                    <td className="px-5 py-4 font-semibold">{account.balance}</td>
                    <td className="px-5 py-4"><Badge tone={account.statusTone}>{account.status}</Badge></td>
                    <td className="px-5 py-4"><Badge tone={account.selfTone}>{account.selfService}</Badge></td>
                    <td className="px-5 py-4 text-slate-600">{account.lastBooking}</td>
                    <td className="px-5 py-4">
                      <div className="flex flex-wrap gap-2">
                        {account.actions.map((action) => (
                          <button key={action} className="rounded-lg border border-slate-300 px-3 py-1 text-xs font-semibold text-slate-700 hover:bg-slate-100">
                            {action}
                          </button>
                        ))}
                      </div>
                    </td>
                  </tr>
                ))}
              </tbody>
            </table>
          </div>
        </section>
      </div>
    </div>
  );
}
