import { h } from "./jsx";
import { Sidebar } from "./components/Sidebar";
import { PaliadinWidget } from "./components/PaliadinWidget";
import { BottomNav } from "./components/BottomNav";
import { Footer } from "./components/Footer";
import { PWAHead } from "./components/PWAHead";

// /admin/rules/export — Slice 11b (t-paliad-192). Surfaces the
// GET /admin/api/rules/export-migrations endpoint as a SQL preview the
// editor can copy or download. Optional ?since=<audit-id> query lets
// the editor scope the export to a particular audit window — empty =
// every un-exported audit row.
export function renderAdminRulesExport(): string {
  return "<!DOCTYPE html>" + (
    <html lang="de">
      <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
        <meta name="theme-color" content="#BFF355" />
        <meta name="apple-mobile-web-app-capable" content="yes" />
        <meta name="apple-mobile-web-app-status-bar-style" content="default" />
        <PWAHead />
        <title data-i18n="admin.rules.export.title">Regel-Migrations exportieren &mdash; Paliad</title>
        <link rel="stylesheet" href="/assets/global.css" />
      </head>
      <body className="has-sidebar">
        <Sidebar currentPath="/admin/rules" />
        <BottomNav currentPath="/admin/rules" />

        <main>
          <section className="tool-page">
            <div className="container">
              <div className="tool-header">
                <div>
                  <p className="admin-rules-breadcrumb">
                    <a href="/admin/rules" data-i18n="admin.rules.export.breadcrumb">&larr; Regeln verwalten</a>
                  </p>
                  <h1 data-i18n="admin.rules.export.heading">Regel-Migrations exportieren</h1>
                  <p className="tool-subtitle" data-i18n="admin.rules.export.subtitle">
                    Generiert ein <code>*.up.sql</code>-Blob mit allen unsynchronisierten Audit-Ver&auml;nderungen.
                    Manuell in <code>internal/db/migrations/</code> einchecken.
                  </p>
                </div>
              </div>

              <div className="admin-rules-export-controls">
                <div className="form-field">
                  <label htmlFor="export-since" data-i18n="admin.rules.export.field.since">Startend ab Audit-ID (optional)</label>
                  <input type="text" id="export-since" className="admin-rules-input" placeholder="UUID, leer = alle un-exportierten" />
                </div>
                <button type="button" id="export-run" className="btn-primary" data-i18n="admin.rules.export.run">
                  Export generieren
                </button>
                <button type="button" id="export-download" className="btn-secondary" style="display:none" data-i18n="admin.rules.export.download">
                  Als Datei herunterladen
                </button>
                <button type="button" id="export-copy" className="btn-secondary" style="display:none" data-i18n="admin.rules.export.copy">
                  In Zwischenablage kopieren
                </button>
              </div>

              <div id="export-feedback" className="form-msg" style="display:none" />

              <div className="admin-rules-export-summary" id="export-summary" style="display:none">
                <span id="export-summary-count" />
                <span id="export-summary-latest" />
              </div>

              <pre id="export-output" className="admin-rules-export-pre" />
            </div>
          </section>
        </main>

        <Footer />
        <PaliadinWidget />
        <script src="/assets/admin-rules-export.js"></script>
      </body>
    </html>
  );
}
