import React from 'react';

const rows = [
  { selected: true, recipient: 'Maria Keller', equipment: 'DT-1004 · Flasche', trigger: 'overdue', due: '2026-04-25', channel: 'E-Mail', template: 'Frist überfällig', status: 'ready', action: 'BN-03', triggerTone: 'red', statusTone: 'green' },
  { selected: false, recipient: 'Sara Frei', equipment: 'DT-1088 · Flasche', trigger: 'due_soon', due: '2026-05-13', channel: 'Portal', template: 'bald fällig', status: 'prüfen', action: 'FR-03', triggerTone: 'yellow', statusTone: 'yellow' },
  { selected: false, recipient: 'Unbekannt', equipment: 'DT-1220 · Regler', trigger: 'unknown', due: '-', channel: 'E-Mail', template: 'Daten prüfen', status: 'blocked', action: 'UC01', triggerTone: 'gray', statusTone: 'red' },
];

const metrics = [
  { label: 'Vorschläge', value: 21, tone: 'blue' },
  { label: 'ready', value: 14, tone: 'green' },
  { label: 'prüfen', value: 5, tone: 'yellow' },
  { label: 'blockiert', value: 2, 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 MetricCard({ label, value, tone }) {
  const tones = {
    green: 'border-green-200 bg-green-50 text-green-900',
    blue: 'border-blue-200 bg-blue-50 text-blue-900',
    yellow: 'border-yellow-200 bg-yellow-50 text-yellow-900',
    red: 'border-red-200 bg-red-50 text-red-900',
  };
  return (
    <div className={`rounded-2xl border p-4 ${tones[tone]}`}>
      <p className="text-3xl font-bold">{value}</p>
      <p className="mt-1 text-sm font-semibold">{label}</p>
    </div>
  );
}

export default function BN02BenachrichtigungsvorschlaegePruefen() {
  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">UC07 · BN-02</p>
              <h1 className="mt-1 text-3xl font-bold">Benachrichtigungsvorschläge prüfen</h1>
              <p className="mt-2 max-w-3xl text-sm text-slate-600">Vorschläge aus UC05 prüfen, blockierte Fälle erkennen und Versand vorbereiten.</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">BN-01</button>
              <button className="rounded-xl border border-slate-300 bg-white px-4 py-2 text-sm font-semibold text-slate-800">BN-03</button>
              <button className="rounded-xl bg-sky-700 px-4 py-2 text-sm font-semibold text-white">Weiter</button>
            </div>
          </div>
        </header>

        <section className="rounded-2xl border border-slate-200 bg-white p-5 shadow-sm">
          <h2 className="text-lg font-bold">Vorschlagsstatus</h2>
          <div className="mt-4 grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
            {metrics.map((metric) => <MetricCard key={metric.label} {...metric} />)}
          </div>
          <p className="mt-3 text-sm text-slate-500">Quelle: UC05 / Fristen · Zeitraum: nächste 30 Tage.</p>
        </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">
            {['Bereitschaft', 'Auslöser', 'Empfänger', 'Kanal', 'Zeitraum'].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="border-b border-slate-200 px-5 py-4">
            <h2 className="text-lg font-bold">Vorschlagsliste</h2>
            <p className="text-sm text-slate-500">BN-02 prüft nur. Versand erfolgt über BN-04 oder BN-05.</p>
          </div>
          <div className="overflow-x-auto">
            <table className="w-full min-w-[1120px] text-left text-sm">
              <thead className="bg-slate-100 text-xs uppercase tracking-wide text-slate-600">
                <tr>
                  <th className="px-5 py-3">Auswahl</th>
                  <th className="px-5 py-3">Empfänger</th>
                  <th className="px-5 py-3">Equipment</th>
                  <th className="px-5 py-3">Auslöser</th>
                  <th className="px-5 py-3">Frist</th>
                  <th className="px-5 py-3">Kanal</th>
                  <th className="px-5 py-3">Vorlage</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">
                {rows.map((row) => (
                  <tr key={`${row.recipient}-${row.equipment}`} className="hover:bg-slate-50">
                    <td className="px-5 py-4 text-slate-600">{row.selected ? '☑' : '☐'}</td>
                    <td className="px-5 py-4 font-semibold">{row.recipient}</td>
                    <td className="px-5 py-4 text-slate-600">{row.equipment}</td>
                    <td className="px-5 py-4"><Badge tone={row.triggerTone}>{row.trigger}</Badge></td>
                    <td className="px-5 py-4 text-slate-600">{row.due}</td>
                    <td className="px-5 py-4 text-slate-600">{row.channel}</td>
                    <td className="px-5 py-4 text-slate-600">{row.template}</td>
                    <td className="px-5 py-4"><Badge tone={row.statusTone}>{row.status}</Badge></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">{row.action}</button></td>
                  </tr>
                ))}
              </tbody>
            </table>
          </div>
        </section>

        <section className="rounded-2xl border border-slate-200 bg-white p-5 shadow-sm">
          <h2 className="text-lg font-bold">Schnellaktionen</h2>
          <div className="mt-4 flex flex-wrap gap-2">
            <button className="rounded-xl border border-slate-300 px-4 py-2 text-sm font-semibold text-slate-700">BN-03 Vorschau</button>
            <button className="rounded-xl border border-slate-300 px-4 py-2 text-sm font-semibold text-slate-700">BN-04 einzeln</button>
            <button className="rounded-xl border border-slate-300 px-4 py-2 text-sm font-semibold text-slate-700">BN-05 sammeln</button>
          </div>
        </section>
      </div>
    </div>
  );
}
