import React from 'react';

const modules = [
  { label: 'UC05', tone: 'green' },
  { label: 'UC06', tone: 'green' },
  { label: 'UC07', tone: 'green' },
  { label: 'UC08 prüfen', tone: 'yellow' },
];

const checks = [
  { label: 'Konfiguration vollständig', tone: 'green' },
  { label: 'UC08 noch prüfen', tone: 'yellow' },
  { label: 'Audit vorhanden', tone: 'blue' },
];

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 Field({ label, value }) {
  return (
    <div>
      <p className="text-xs font-semibold uppercase tracking-wide text-slate-500">{label}</p>
      <div className="mt-1 rounded-xl border border-slate-300 bg-slate-50 px-4 py-2 text-sm text-slate-800">{value}</div>
    </div>
  );
}

export default function SA03TenantDetailKonfiguration() {
  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">UC-SA · SA-03</p>
              <h1 className="mt-1 text-3xl font-bold">Tenant-Detail & Konfiguration</h1>
              <p className="mt-2 max-w-3xl text-sm text-slate-600">Mandantenhülle prüfen: Stammdaten, Status, Module, Limits und Support.</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">SA-02</button>
              <button className="rounded-xl border border-slate-300 bg-white px-4 py-2 text-sm font-semibold text-slate-800">SA-08</button>
              <button className="rounded-xl bg-sky-700 px-4 py-2 text-sm font-semibold text-white">Speichern</button>
            </div>
          </div>
        </header>

        <div className="grid gap-5 lg:grid-cols-2">
          <Card title="Tenant-Stammdaten">
            <div className="space-y-4">
              <Field label="Tenant-ID" value="tenant_hochrhein" />
              <Field label="Name" value="Tauchschule Hochrhein" />
              <Field label="Domain" value="hochrhein.divelogix360.ch" />
              <Field label="Kontakt" value="info@example.test" />
            </div>
          </Card>

          <Card title="Status und Module">
            <div className="flex flex-wrap gap-2">
              <Badge tone="green">active</Badge>
              <Badge tone="blue">Support erlaubt</Badge>
              {modules.map((module) => <Badge key={module.label} tone={module.tone}>{module.label}</Badge>)}
            </div>
            <p className="mt-4 text-sm text-slate-500">Statusaktionen erfolgen nur über SA-05.</p>
          </Card>
        </div>

        <div className="grid gap-5 lg:grid-cols-2">
          <Card title="Limits und Konfiguration">
            <div className="space-y-2 text-sm text-slate-700">
              <p>Benutzerlimit: 25</p>
              <p>Kundenlimit: 2'000</p>
              <p>Equipmentlimit: 5'000</p>
              <p>Portal-Einladung: 14 Tage gültig</p>
            </div>
          </Card>

          <Card title="Risiken und Prüfungen">
            <div className="flex flex-wrap gap-2">
              {checks.map((check) => <Badge key={check.label} tone={check.tone}>{check.label}</Badge>)}
            </div>
          </Card>
        </div>

        <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">SA-05 Status</button>
            <button className="rounded-xl border border-slate-300 px-4 py-2 text-sm font-semibold text-slate-700">SA-06 Vorlagen</button>
            <button className="rounded-xl border border-slate-300 px-4 py-2 text-sm font-semibold text-slate-700">SA-07 Support</button>
            <button className="rounded-xl bg-sky-700 px-4 py-2 text-sm font-semibold text-white">SA-08 Audit</button>
          </div>
          <p className="mt-4 text-sm text-slate-500">Keine operative Kunden- oder Equipmentverwaltung.</p>
        </section>

        <section className="rounded-2xl border border-slate-200 bg-white p-5 shadow-sm">
          <h2 className="text-lg font-bold">Sicherheit</h2>
          <p className="mt-2 text-sm text-slate-600">Änderungen an Tenant-Grunddaten werden protokolliert. Gefährliche Aktionen benötigen Bestätigung.</p>
        </section>
      </div>
    </div>
  );
}
