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

export function renderAdminAuditLog(): 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.audit.title">Audit-Log &mdash; Paliad</title>
        <link rel="stylesheet" href="/assets/global.css" />
      </head>
      <body className="has-sidebar">
        <Sidebar currentPath="/admin/audit-log" />
        <BottomNav currentPath="/admin/audit-log" />

        <main>
          <section className="tool-page">
            <div className="container">
              <div className="tool-header">
                <div>
                  <h1 data-i18n="admin.audit.heading">Audit-Log</h1>
                  <p className="tool-subtitle" data-i18n="admin.audit.subtitle">
                    Globale Zeitleiste &uuml;ber Projekt-, CalDAV- und Reminder-Ereignisse.
                  </p>
                </div>
              </div>

              <div className="admin-audit-controls">
                <div className="admin-audit-control-row">
                  <div className="admin-audit-field">
                    <label htmlFor="audit-source" data-i18n="admin.audit.filter.source">Quelle</label>
                    <select id="audit-source" className="admin-audit-input">
                      <option value="" data-i18n="admin.audit.source.all">Alle</option>
                      <option value="project_events" data-i18n="admin.audit.source.project_events">Projekt-Ereignisse</option>
                      <option value="caldav_sync_log" data-i18n="admin.audit.source.caldav_sync_log">CalDAV-Sync</option>
                      <option value="reminder_log" data-i18n="admin.audit.source.reminder_log">Reminder</option>
                    </select>
                  </div>

                  <div className="admin-audit-field">
                    <label htmlFor="audit-range" data-i18n="admin.audit.filter.range">Zeitraum</label>
                    <select id="audit-range" className="admin-audit-input">
                      <option value="24h" data-i18n="admin.audit.range.24h">Letzte 24h</option>
                      <option value="7d" selected data-i18n="admin.audit.range.7d">Letzte 7 Tage</option>
                      <option value="30d" data-i18n="admin.audit.range.30d">Letzte 30 Tage</option>
                      <option value="custom" data-i18n="admin.audit.range.custom">Benutzerdefiniert</option>
                      <option value="all" data-i18n="admin.audit.range.all">Alles</option>
                    </select>
                  </div>

                  <div className="admin-audit-field admin-audit-custom-range" id="audit-custom-range" style="display:none">
                    <label htmlFor="audit-from" data-i18n="admin.audit.filter.from">Von</label>
                    <input type="date" lang="de" id="audit-from" className="admin-audit-input" />
                    <label htmlFor="audit-to" data-i18n="admin.audit.filter.to">Bis</label>
                    <input type="date" lang="de" id="audit-to" className="admin-audit-input" />
                  </div>
                </div>

                <div className="admin-audit-control-row">
                  <div className="admin-audit-field admin-audit-search-field">
                    <label htmlFor="audit-search" data-i18n="admin.audit.filter.search">Suche</label>
                    <input
                      type="text"
                      id="audit-search"
                      className="admin-audit-input"
                      placeholder="Subjekt, Beschreibung, Ereignistyp ..."
                      data-i18n-placeholder="admin.audit.search.placeholder"
                      autocomplete="off"
                    />
                  </div>
                  <div className="admin-audit-field admin-audit-counter-field">
                    <span className="admin-audit-counter" id="audit-count">&nbsp;</span>
                  </div>
                </div>
              </div>

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

              <div className="entity-table-wrap admin-audit-table-wrap">
                <table className="entity-table entity-table--readonly admin-audit-table">
                  <thead>
                    <tr>
                      <th data-i18n="admin.audit.col.time">Zeit</th>
                      <th data-i18n="admin.audit.col.source">Quelle</th>
                      <th data-i18n="admin.audit.col.event">Ereignis</th>
                      <th data-i18n="admin.audit.col.actor">Akteur</th>
                      <th data-i18n="admin.audit.col.subject">Subjekt</th>
                      <th data-i18n="admin.audit.col.description">Beschreibung</th>
                    </tr>
                  </thead>
                  <tbody id="audit-tbody">
                    <tr><td colspan={6} className="admin-audit-loading" data-i18n="admin.audit.loading">Lade ...</td></tr>
                  </tbody>
                </table>
              </div>

              <div className="entity-empty" id="audit-empty" style="display:none">
                <p data-i18n="admin.audit.empty">Keine Ereignisse f&uuml;r die gew&auml;hlten Filter.</p>
              </div>

              <div className="admin-audit-pagination">
                <button type="button" id="audit-loadmore" className="btn-secondary" style="display:none" data-i18n="admin.audit.loadmore">
                  Weitere laden
                </button>
              </div>
            </div>
          </section>
        </main>

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