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

// The /*__PALIAD_AGENDA_DATA__*/ token is replaced at request time by the Go
// handler (internal/handlers/agenda_shell.go) with a JSON payload assigned
// to window.__PALIAD_AGENDA__. Keep the token intact and exactly once.
const HYDRATION_SCRIPT = "/*__PALIAD_AGENDA_DATA__*/";

export function renderAgenda(): 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="agenda.title">Agenda &mdash; Paliad</title>
        <link rel="stylesheet" href="/assets/global.css" />
        <script dangerouslySetInnerHTML={{ __html: HYDRATION_SCRIPT }} />
      </head>
      <body className="has-sidebar">
        <Sidebar currentPath="/agenda" />
        <BottomNav currentPath="/agenda" />

        <main>
          <section className="tool-page">
            <div className="container">
              <div className="tool-header">
                <div className="entity-header-row">
                  <div>
                    <h1 data-i18n="agenda.heading">Agenda</h1>
                    <p className="tool-subtitle" data-i18n="agenda.subtitle">
                      Kommende Fristen und Termine &uuml;ber alle sichtbaren Akten, nach Tag gruppiert.
                    </p>
                  </div>
                </div>
              </div>

              <div id="agenda-unavailable" className="entity-unavailable" style="display:none">
                <p data-i18n="agenda.unavailable">
                  Agenda zurzeit nicht verf&uuml;gbar &mdash; bitte Administrator kontaktieren.
                </p>
              </div>

              <div className="agenda-controls">
                <div className="agenda-filter-group" role="group" aria-labelledby="agenda-type-heading">
                  <span id="agenda-type-heading" className="agenda-filter-label" data-i18n="agenda.filter.type">Ansicht</span>
                  <div className="agenda-chip-row">
                    <button type="button" className="agenda-chip" data-type="both" data-i18n="agenda.filter.both">Beides</button>
                    <button type="button" className="agenda-chip" data-type="deadlines" data-i18n="agenda.filter.deadlines">Nur Fristen</button>
                    <button type="button" className="agenda-chip" data-type="appointments" data-i18n="agenda.filter.appointments">Nur Termine</button>
                  </div>
                </div>

                <div className="agenda-filter-group" role="group" aria-labelledby="agenda-range-heading">
                  <span id="agenda-range-heading" className="agenda-filter-label" data-i18n="agenda.filter.range">Zeitraum</span>
                  <div className="agenda-chip-row">
                    <button type="button" className="agenda-chip" data-range="7" data-i18n="agenda.range.7">7 Tage</button>
                    <button type="button" className="agenda-chip" data-range="14" data-i18n="agenda.range.14">14 Tage</button>
                    <button type="button" className="agenda-chip" data-range="30" data-i18n="agenda.range.30">30 Tage</button>
                    <button type="button" className="agenda-chip" data-range="90" data-i18n="agenda.range.90">90 Tage</button>
                  </div>
                </div>

                <div className="agenda-filter-group">
                  <label className="agenda-filter-label" htmlFor="agenda-filter-event-type" data-i18n="agenda.filter.event_type">Typ</label>
                  <button type="button" id="agenda-filter-event-type" className="entity-select multi-trigger" aria-haspopup="listbox" />
                  <div id="agenda-filter-event-type-panel" className="multi-panel" hidden />
                </div>
              </div>

              <div className="agenda-loading" id="agenda-loading" style="display:none" data-i18n="agenda.loading">
                L&auml;dt &hellip;
              </div>

              <div className="agenda-timeline" id="agenda-timeline" />

              <div className="entity-empty" id="agenda-empty" style="display:none">
                <h2 data-i18n="agenda.empty.title">Keine Eintr&auml;ge im Zeitraum</h2>
                <p data-i18n="agenda.empty.hint">
                  Nichts F&auml;lliges &mdash; erweitern Sie den Zeitraum oder legen Sie neue Fristen oder Termine an.
                </p>
              </div>
            </div>
          </section>
        </main>

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