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";

// Backup Mode admin page (t-paliad-246 / m/paliad#77 Slice A).
//
// global_admin only — gated by adminGate(...) in handlers.go. Shows the
// chronological list of backup runs (one row per kind in
// {scheduled, on_demand}) plus a button to kick off an on-demand backup.
// Catalog rows + the "run now" action are fetched client-side via
// /api/admin/backups.
export function renderAdminBackups(): 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.backups.title">Backups &mdash; Paliad</title>
        <link rel="stylesheet" href="/assets/global.css" />
      </head>
      <body className="has-sidebar">
        <Sidebar currentPath="/admin/backups" />
        <BottomNav currentPath="/admin/backups" />

        <main>
          <section className="tool-page">
            <div className="container">
              <div className="tool-header">
                <div>
                  <h1 data-i18n="admin.backups.heading">Backups</h1>
                  <p className="tool-subtitle" data-i18n="admin.backups.subtitle">
                    Vollst&auml;ndige Snapshots aller Daten &mdash; manuell oder zeitgesteuert.
                  </p>
                </div>
                <div>
                  <button
                    className="btn-primary"
                    id="admin-backups-run-btn"
                    type="button"
                    data-i18n="admin.backups.run_now"
                  >
                    Backup jetzt erstellen
                  </button>
                </div>
              </div>

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

              <div className="entity-table-wrap">
                <table className="entity-table entity-table--readonly">
                  <thead>
                    <tr>
                      <th data-i18n="admin.backups.col.started">Erstellt</th>
                      <th data-i18n="admin.backups.col.kind">Auslöser</th>
                      <th data-i18n="admin.backups.col.status">Status</th>
                      <th data-i18n="admin.backups.col.requested_by">Angefordert von</th>
                      <th data-i18n="admin.backups.col.size">Gr&ouml;&szlig;e</th>
                      <th data-i18n="admin.backups.col.rows">Zeilen</th>
                      <th data-i18n="admin.backups.col.actions">Aktion</th>
                    </tr>
                  </thead>
                  <tbody id="admin-backups-tbody">
                    <tr>
                      <td colspan={7} data-i18n="admin.backups.loading">Lade &hellip;</td>
                    </tr>
                  </tbody>
                </table>
              </div>

              <div className="entity-empty" id="admin-backups-empty" style="display:none">
                <p data-i18n="admin.backups.empty">Noch keine Backups vorhanden.</p>
              </div>

              <p className="tool-footer-note" id="admin-backups-footer">
                <span data-i18n="admin.backups.footer.note">
                  Geplante Backups werden in einer sp&auml;teren Slice aktiviert. Manuelle Backups stehen jetzt zur Verf&uuml;gung.
                </span>
              </p>
            </div>
          </section>
        </main>

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