import React from 'react';

const rows = [
  { prio: 'hoch', status: 'overdue', equipment: 'DT-1004 · Flasche', customer: 'Maria Keller', due: '2026-04-25', days: '-12', workflow: 'keiner', notification: 'offen', action: 'FR-03', tone: 'red' },
  { prio: 'hoch', status: 'blocked', equipment: 'DT-1011 · Flasche', customer: 'Luca Meier', due: '2026-04-18', days: '-19', workflow: 'in Prüfung', notification: 'offen', action: 'Workflow', tone: 'red' },
  { prio: 'mittel', status: 'due_today', equipment: 'DT-1032 · Flasche', customer: 'Nina Graf', due: '2026-05-07', days: '0', workflow: 'keiner', notification: 'keine', action: 'FR-03', tone: 'orange' },
  { prio: 'normal', status: 'due_soon', equipment: 'DT-1088 · Flasche', customer: 'Sara Frei', due: '2026-05-13', days: '6', workflow: 'keiner', notification: 'geplant', action: 'FR-03', tone: 'yellow' },
  { prio: 'prüfen', status: 'unknown', equipment: 'DT-1220 · Regler', customer: 'Unbekannt', due: '-', days: '-', workflow: 'keiner', notification: 'keine', action: 'prüfen', 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',
    orange: 'bg-orange-100 text-orange-800 border-orange-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>;
}

export default function FR02FristenlisteArbeitsliste() {
  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-02</p>
              <h1 className="mt-1 text-3xl font-bold">Fristenliste / Arbeitsliste</h1>
              <p className="mt-2 max-w-3xl text-sm text-slate-600">Tabellarische Arbeitsliste mit Status, Priorität, Equipment, Kunde und nächster Frist.</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">FR-01</button>
              <button className="rounded-xl border border-slate-300 bg-white px-4 py-2 text-sm font-semibold text-slate-800">FR-07</button>
              <button className="rounded-xl bg-sky-700 px-4 py-2 text-sm font-semibold text-white">Export</button>
            </div>
          </div>
        </header>

        <section className="rounded-2xl border border-slate-200 bg-white p-5 shadow-sm">
          <h2 className="text-lg font-bold">Filter & Sortierung</h2>
          <div className="mt-4 grid gap-3 lg:grid-cols-6">
            {['30 Tage', 'Status', 'Equipment-Typ', 'Kunde', 'Workflow'].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>
          <p className="mt-3 text-sm text-slate-500">Sortierung: Priorität, dann nächste Frist · Treffer: 35 · Stand: 2026-05-07 09:30</p>
        </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">Fristenliste</h2>
            <p className="text-sm text-slate-500">Read-only: keine direkte Änderung an Fristgrundlagen.</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">Prio</th>
                  <th className="px-5 py-3">Status</th>
                  <th className="px-5 py-3">Equipment</th>
                  <th className="px-5 py-3">Kunde</th>
                  <th className="px-5 py-3">nächste Frist</th>
                  <th className="px-5 py-3">Tage</th>
                  <th className="px-5 py-3">Workflow</th>
                  <th className="px-5 py-3">Benachrichtigung</th>
                  <th className="px-5 py-3">Aktion</th>
                </tr>
              </thead>
              <tbody className="divide-y divide-slate-100">
                {rows.map((row) => (
                  <tr key={`${row.equipment}-${row.status}`} className="hover:bg-slate-50">
                    <td className="px-5 py-4"><Badge tone={row.tone}>{row.prio}</Badge></td>
                    <td className="px-5 py-4"><Badge tone={row.tone}>{row.status}</Badge></td>
                    <td className="px-5 py-4 font-semibold">{row.equipment}</td>
                    <td className="px-5 py-4 text-slate-600">{row.customer}</td>
                    <td className="px-5 py-4 text-slate-600">{row.due}</td>
                    <td className="px-5 py-4 text-slate-600">{row.days}</td>
                    <td className="px-5 py-4 text-slate-600">{row.workflow}</td>
                    <td className="px-5 py-4 text-slate-600">{row.notification}</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">FR-04 kritisch</button>
            <button className="rounded-xl border border-slate-300 px-4 py-2 text-sm font-semibold text-slate-700">FR-05 bald</button>
            <button className="rounded-xl border border-slate-300 px-4 py-2 text-sm font-semibold text-slate-700">FR-07 Vorschau</button>
            <button className="rounded-xl border border-slate-300 px-4 py-2 text-sm font-semibold text-slate-700">FR-08 Export</button>
          </div>
        </section>
      </div>
    </div>
  );
}
