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 renderDeadlinesNew(): 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="deadlines.neu.title">Neue Frist &mdash; Paliad</title>
        <link rel="stylesheet" href="/assets/global.css" />
      </head>
      <body className="has-sidebar">
        <Sidebar currentPath="/events?type=deadline" />
        <BottomNav currentPath="/events?type=deadline" />

        <main>
          <section className="tool-page">
            <div className="container container-narrow">
              <div className="tool-header">
                <a href="/events?type=deadline" className="back-link" id="deadline-new-back" data-i18n="deadlines.neu.back">&larr; Zur&uuml;ck zur &Uuml;bersicht</a>
                <h1 data-i18n="deadlines.neu.heading">Neue Frist anlegen</h1>
                <p className="tool-subtitle" data-i18n="deadlines.neu.subtitle">
                  Eine persistente Frist an einer Akte. Sichtbar f&uuml;r alle Personen, die die Akte sehen k&ouml;nnen.
                </p>
              </div>

              <form id="deadline-new-form" className="entity-form" autocomplete="off">
                <div className="form-field">
                  <label htmlFor="deadline-project" data-i18n="deadlines.field.akte">Akte</label>
                  <select id="deadline-project" required>
                    <option value="" disabled selected data-i18n="deadlines.field.akte.choose">Bitte w&auml;hlen&hellip;</option>
                  </select>
                  <p className="form-hint" id="deadline-project-empty-hint" style="display:none" data-i18n="deadlines.field.akte.empty">
                    Sie haben noch keine Akte. Bitte zuerst eine Akte anlegen.
                  </p>
                </div>

                <div className="form-field">
                  <label htmlFor="deadline-title" data-i18n="deadlines.field.title">Titel</label>
                  <input
                    type="text"
                    id="deadline-title"
                    required
                    placeholder="z.B. Klageerwiderung einreichen"
                    data-i18n-placeholder="deadlines.field.title.placeholder"
                  />
                </div>

                <div className="form-field" id="deadline-event-type-field">
                  <label data-i18n="deadlines.field.event_type">Typ (optional)</label>
                  {/* t-paliad-165 follow-up — collapsed view: when a Regel
                      is selected and a default event_type is known, the
                      Typ chip is hidden and the type is rendered inline
                      as a single read-only summary with an "Anderen Typ
                      wählen" link that re-expands the picker. */}
                  <div
                    className="event-type-collapsed"
                    id="deadline-event-type-collapsed"
                    style="display:none"
                  >
                    <span
                      className="event-type-collapsed-label"
                      id="deadline-event-type-collapsed-label"
                    />
                    <span
                      className="event-type-collapsed-source"
                      data-i18n="deadlines.field.rule.autofill_inline"
                    >
                      &nbsp;(vorgegeben durch Regel)
                    </span>
                    <button
                      type="button"
                      className="event-type-collapsed-override"
                      id="deadline-event-type-override-btn"
                      data-i18n="deadlines.field.rule.override"
                    >
                      Anderen Typ w&auml;hlen
                    </button>
                  </div>
                  <div id="deadline-event-types" className="event-type-picker-host" />
                  {/* Soft warning when the user is in expanded mode AND
                      has picked an event_type that doesn't include the
                      rule's canonical default. Reuses the existing
                      yellow form-hint--warning style; never blocking. */}
                  <p
                    className="form-hint form-hint--warning"
                    id="deadline-event-type-rule-mismatch"
                    style="display:none"
                    data-i18n="deadlines.field.rule.mismatch"
                  >
                    Hinweis: Typ widerspricht Regel &mdash; Sie haben den Typ &uuml;berschrieben.
                  </p>
                </div>

                {/* m/paliad#56 — Regel sits directly beneath the Typ
                    picker so the parent/child relationship reads at a
                    glance. Due date is its own row below. */}
                <div className="form-field">
                  <label htmlFor="deadline-rule" data-i18n="deadlines.field.rule">Regel (optional)</label>
                  <select id="deadline-rule">
                    <option value="" data-i18n="deadlines.field.rule.none">Keine Regel</option>
                  </select>
                </div>

                <div className="form-field">
                  <label htmlFor="deadline-due" data-i18n="deadlines.field.due">F&auml;lligkeitsdatum</label>
                  <input type="date" id="deadline-due" required />
                </div>

                <div className="form-field">
                  <label htmlFor="deadline-notes" data-i18n="deadlines.field.notes">Notizen (optional)</label>
                  <textarea id="deadline-notes" rows={3} placeholder="Hinweise, Verweise, n&auml;chste Schritte&hellip;" data-i18n-placeholder="deadlines.field.notes.placeholder" />
                </div>

                <p className="form-msg" id="deadline-new-msg" />

                {/* t-paliad-154 — form-time 4-eye hint. Hidden by default;
                    revealed by client TS when an effective policy applies
                    to the chosen project. */}
                <div className="approval-hint" id="deadline-approval-hint" style="display:none">
                  <span className="approval-hint-icon" dangerouslySetInnerHTML={{
                    __html: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg>'
                  }} />
                  <span id="deadline-approval-hint-text" />
                </div>

                <div className="form-actions">
                  <a href="/events?type=deadline" id="deadline-new-cancel" className="btn-cancel" data-i18n="deadlines.neu.cancel">Abbrechen</a>
                  <button type="submit" className="btn-primary btn-cta-lime" data-i18n="deadlines.neu.submit">Frist anlegen</button>
                </div>
              </form>
            </div>
          </section>
        </main>

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