import React from 'react';

const fieldGroups = [
  { label: 'Equipment', tone: 'green' },
  { label: 'Kunde', tone: 'yellow' },
  { label: 'Frist', tone: 'green' },
  { label: 'Workflow', tone: 'blue' },
  { label: 'Benachrichtigung', tone: 'gray' },
];

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 Card({ title, children }) {
  return (
    <section className="rounded-2xl border border-slate-200 bg-white p-5 shadow-sm">
      <h2 className="text-lg font-bold">{title}</h2>
      <div className="mt-4">{children}</div>
    </section>
  );
}

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',
    gray: 'border-slate-200 bg-slate-50 text-slate-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 FR08FristenexportVorbereiten() {
  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">UC05 · FR-08</p>
              <h1 className="mt-1 text-3xl font-bold">Fristenexport vorbereiten</h1>
              <p className="mt-2 max-w-3xl text-sm text-slate-600">Exportumfang prüfen und an UC09 – Berichte & Export übergeben.</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">Zurück</button>
              <button className="rounded-xl border border-slate-300 bg-white px-4 py-2 text-sm font-semibold text-slate-800">FR-02</button>
              <button className="rounded-xl bg-sky-700 px-4 py-2 text-sm font-semibold text-white">UC09 öffnen</button>
            </div>
          </div>
        </header>

        <section className="rounded-2xl border border-slate-200 bg-white p-5 shadow-sm">
          <h2 className="text-lg font-bold">Exportkontext</h2>
          <div className="mt-4 grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
            <MetricCard label="Datensätze" value="35" tone="blue" />
            <MetricCard label="Berechtigung" value="OK" tone="green" />
            <MetricCard label="Datenschutz" value="prüfen" tone="yellow" />
            <MetricCard label="Quelle" value="FR-02" tone="gray" />
          </div>
          <p className="mt-3 text-sm text-slate-500">Finaler Export, Download und Protokollierung erfolgen in UC09.</p>
        </section>

        <div className="grid gap-5 lg:grid-cols-2">
          <Card title="Filterzusammenfassung">
            <div className="space-y-3 text-sm text-slate-700">
              <p>Zeitraum: nächste 30 Tage</p>
              <p>Status: due_soon, due_today, overdue, blocked</p>
              <p>Equipment-Typ: Flasche</p>
              <p>Kunde: alle</p>
              <p>Sortierung: Priorität, dann nächste Frist</p>
            </div>
          </Card>

          <Card title="Feldgruppen">
            <div className="flex flex-wrap gap-2">
              {fieldGroups.map((group) => <Badge key={group.label} tone={group.tone}>{group.label}</Badge>)}
            </div>
            <div className="mt-4 rounded-xl border border-yellow-200 bg-yellow-50 p-3 text-sm text-yellow-900">Kundendaten im Export enthalten – Datenschutz prüfen.</div>
          </Card>
        </div>

        <div className="grid gap-5 lg:grid-cols-2">
          <Card title="Datenschutz & Rechte">
            <ul className="list-disc space-y-2 pl-5 text-sm text-slate-700">
              <li>Tenant-Isolation: OK.</li>
              <li>Rolle: tenant_admin – Exportvorbereitung erlaubt.</li>
              <li>Kundendaten: prüfen / ggf. reduzieren.</li>
              <li>Download wird in UC05 nicht erstellt.</li>
            </ul>
          </Card>

          <Card title="Übergabe an UC09">
            <div className="space-y-3 text-sm text-slate-700">
              <p>Exporttyp: gefilterte Fristenliste.</p>
              <p>Übergabe: Filter, Feldgruppen, Anzahl, Kontext.</p>
              <p>UC09 übernimmt Datei, Format, Download und Protokoll.</p>
            </div>
            <div className="mt-4 flex justify-end">
              <button className="rounded-xl bg-sky-700 px-4 py-2 text-sm font-semibold text-white">UC09 öffnen</button>
            </div>
          </Card>
        </div>

        <section className="rounded-2xl border border-slate-200 bg-white p-5 shadow-sm">
          <p className="text-sm text-slate-600">FR-08 ist Vorbereitung. Keine finale Exportdatei, kein Download und keine Exportprotokollierung in UC05.</p>
        </section>
      </div>
    </div>
  );
}
