import React from 'react';

const rows = [
  { group: 'heute', prio: 'mittel', status: 'due_today', equipment: 'DT-1032 · Flasche', customer: 'Nina Graf', due: '2026-05-07', days: '0', workflow: 'keiner', notification: 'offen', action: 'FR-03', tone: 'orange' },
  { group: '7 Tage', 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' },
  { group: '30 Tage', prio: 'normal', status: 'due_soon', equipment: 'DT-1120 · Flasche', customer: 'Marco Lang', due: '2026-05-21', days: '14', workflow: 'geplant', notification: 'offen', action: 'FR-03', tone: 'yellow' },
];

const metrics = [
  { label: 'heute fällig', value: 2, tone: 'orange' },
  { label: 'in 7 Tagen', value: 6, tone: 'yellow' },
  { label: 'in 30 Tagen', value: 18, tone: 'yellow' },
  { label: 'mit Workflow', value: 5, tone: 'blue' },
  { label: 'ohne Workflow', value: 9, tone: 'gray' },
];

function Badge({ children, tone = 'gray' }) {
  const tones = {
    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',
    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 = {
    blue: 'border-blue-200 bg-blue-50 text-blue-900',
    yellow: 'border-yellow-200 bg-yellow-50 text-yellow-900',
    orange: 'border-orange-200 bg-orange-50 text-orange-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 FR05BaldFaelligeFristen() {
  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-05</p>
              <h1 className="mt-1 text-3xl font-bold">Bald fällige Fristen</h1>
              <p className="mt-2 max-w-3xl text-sm text-slate-600">Planungsansicht für kommende Fristen innerhalb des Warnzeitraums.</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-02</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">Planungskennzahlen</h2>
          <div className="mt-4 grid gap-4 sm:grid-cols-2 lg:grid-cols-5">
            {metrics.map((metric) => <MetricCard key={metric.label} {...metric} />)}
          </div>
          <p className="mt-3 text-sm text-slate-500">Standard: 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">
            {['30 Tage', 'Flaschen', 'Kunde', 'Workflow', 'Benachr.'].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">Planungsliste</h2>
            <p className="text-sm text-slate-500">Read-only: Planung ohne 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">Gruppe</th>
                  <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">Frist</th>
                  <th className="px-5 py-3">Tage</th>
                  <th className="px-5 py-3">Workflow</th>
                  <th className="px-5 py-3">Benachr.</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.due}`} className="hover:bg-slate-50">
                    <td className="px-5 py-4 text-slate-600">{row.group}</td>
                    <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-02 Liste</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>
  );
}
