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">
                  <div className="form-field-label-row">
                    <label htmlFor="deadline-title" data-i18n="deadlines.field.title">Titel</label>
                    {/* t-paliad-251 Part 4 — derive a Standardtitel from the
                        currently-known context (event type → rule → proceeding
                        type → fallback) with the project reference as suffix.
                        Always replaces the title; no destructive confirmation
                        because the user invoked it explicitly. */}
                    <button
                      type="button"
                      id="deadline-title-default-btn"
                      className="btn-link-action"
                      data-i18n="deadlines.field.title.default_btn"
                    >
                      Standardtitel
                    </button>
                  </div>
                  <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>
                  <div id="deadline-event-types" className="event-type-picker-host" />
                </div>

                {/* t-paliad-258 / m/paliad#89 — binary Rule field.
                    Auto (default): rule_id derived from the chosen
                    Type, displayed read-only with a canonical
                    "Name · Citation" label. Custom: free-text input,
                    no catalog FK. Toggle switches modes. */}
                <div className="form-field">
                  <div className="form-field-label-row">
                    <label data-i18n="deadlines.field.rule">Regel</label>
                    <button
                      type="button"
                      id="deadline-rule-mode-toggle"
                      className="btn-link-action"
                      data-i18n="deadlines.field.rule.mode.toggle_to_custom"
                    >
                      Eigene Regel eingeben
                    </button>
                  </div>
                  <div className="rule-mode-auto" id="deadline-rule-auto-display">
                    <span
                      className="form-hint-badge"
                      data-i18n="deadlines.field.rule.auto_badge"
                    >Auto</span>
                    <span id="deadline-rule-auto-text" className="rule-auto-text">&mdash;</span>
                  </div>
                  <input
                    type="text"
                    id="deadline-rule-custom-input"
                    className="rule-mode-custom"
                    style="display:none"
                    placeholder="z.B. interner Review-Termin"
                    data-i18n-placeholder="deadlines.field.rule.custom_placeholder"
                    maxLength={200}
                  />
                </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>
  );
}
