{% extends "base.html" %}
{% from "partials/macros.html" import nav_icon %}
{% block title %}Quick-Wins · Putzliga{% endblock %}
{% block page_title %}Quick-Wins{% endblock %}
{% block content %}
  <section class="settings-tabs">
    {% for endpoint, label, icon in settings_tabs %}
      <a href="{{ url_for(endpoint) }}" class="settings-tab {% if active_settings_tab == endpoint %}is-active{% endif %}">
        {{ nav_icon(icon) }}
        <span>{{ label }}</span>
      </a>
    {% endfor %}
  </section>

  <section class="two-column">
    <article class="panel">
      <p class="eyebrow">Gemeinsame Vorlagen</p>
      <h2>Quick-Win anlegen</h2>
      <p class="muted">Alle hier angelegten Quick-Wins sind direkt für das ganze Team im Plus-Menü verfügbar.</p>
      <form method="post" class="form-grid">
        {{ quick_win_form.hidden_tag() }}
        <div class="field">
          {{ quick_win_form.title.label }}
          {{ quick_win_form.title(placeholder="Zum Beispiel: Müllbeutel wechseln") }}
          {% for error in quick_win_form.title.errors %}<small class="error">{{ error }}</small>{% endfor %}
        </div>
        <div class="field">
          {{ quick_win_form.effort.label }}
          {{ quick_win_form.effort() }}
          {% for error in quick_win_form.effort.errors %}<small class="error">{{ error }}</small>{% endfor %}
        </div>
        {{ quick_win_form.submit(class_='button') }}
      </form>
    </article>

    <article class="panel">
      <p class="eyebrow">Direkt sichtbar</p>
      <h2>Aktive Quick-Wins bearbeiten</h2>
      <p class="muted">Per Drag & Drop kannst du die Reihenfolge festlegen, die später auch bei den Quick-Win-Chips erscheint.</p>
      <form method="post" action="{{ url_for('settings.reorder_quick_wins') }}" id="quickWinSortForm">
        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
        <input type="hidden" name="ids" id="quickWinSortIds" value="{{ quick_wins|map(attribute='id')|join(',') }}">
      </form>
      <div class="quick-win-list__toolbar">
        <button type="submit" class="button button--secondary" id="quickWinSortSave" form="quickWinSortForm" disabled>Reihenfolge speichern</button>
      </div>
      <div class="quick-win-list" data-quick-win-sort-list>
        {% for quick_win in quick_wins %}
          <article class="quick-win-manage-card" draggable="true" data-quick-win-sort-item="{{ quick_win.id }}">
            <div class="quick-win-manage-card__summary">
              <div class="quick-win-manage-card__drag">
                {{ nav_icon('list') }}
                <span>Ziehen zum Sortieren</span>
              </div>
              <div class="quick-win-manage-card__title">
                <strong>{{ quick_win.title }}</strong>
              </div>
              <div class="quick-win-manage-card__actions">
                <button
                  type="button"
                  class="button button--ghost"
                  data-quick-win-toggle
                  data-target="quick-win-edit-{{ quick_win.id }}"
                  aria-expanded="false"
                  aria-controls="quick-win-edit-{{ quick_win.id }}"
                >
                  Bearbeiten
                </button>
              </div>
            </div>
            <form
              method="post"
              action="{{ url_for('settings.update_quick_win', quick_win_id=quick_win.id) }}"
              class="quick-win-manage-form"
              id="quick-win-edit-{{ quick_win.id }}"
              data-quick-win-edit
              hidden
            >
              <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
              <div class="field">
                <label for="quick-win-title-{{ quick_win.id }}">Titel</label>
                <input id="quick-win-title-{{ quick_win.id }}" type="text" name="title" value="{{ quick_win.title }}" minlength="2" maxlength="160" required>
              </div>
              <div class="field">
                <label for="quick-win-effort-{{ quick_win.id }}">Aufwand</label>
                <select id="quick-win-effort-{{ quick_win.id }}" name="effort" required>
                  {% for effort_key, effort_values in quick_task_config.items() %}
                    <option value="{{ effort_key }}" {% if quick_win.effort == effort_key %}selected{% endif %}>{{ effort_values.label }}</option>
                  {% endfor %}
                </select>
              </div>
              <p class="muted">Von {{ quick_win.created_by_user.name }}</p>
              <div class="quick-win-manage-card__actions">
                <button type="submit" class="button button--secondary">Speichern</button>
                {% if quick_win.created_by_user_id == current_user.id or current_user.is_admin %}
                  <button
                    type="submit"
                    class="button button--ghost"
                    formaction="{{ url_for('settings.delete_quick_win', quick_win_id=quick_win.id) }}"
                    formmethod="post"
                  >
                    Entfernen
                  </button>
                {% endif %}
              </div>
            </form>
          </article>
        {% else %}
          <div class="empty-state">Noch keine Quick-Wins angelegt. Der erste steht gleich oben bereit.</div>
        {% endfor %}
      </div>
    </article>
  </section>

  {% if current_user.is_admin %}
    <section class="panel">
      <p class="eyebrow">Admin</p>
      <h2>Quick-Win-Aufwand</h2>
      <p class="muted">Hier definierst du die sichtbaren Aufwand-Stufen und die dazugehörigen Punkte. Im Quick-Wins-Dialog wird nur die Bezeichnung angezeigt.</p>
      <form method="post" action="{{ url_for('settings.update_quick_task_config') }}" class="badge-settings">
        {{ quick_task_config_form.hidden_tag() }}
        <div class="badge-setting-card">
          <div>
            <strong>Slot 1</strong>
            <p class="muted">Kleine Sache für zwischendurch.</p>
          </div>
          <div class="field">
            {{ quick_task_config_form.fast_label.label }}
            {{ quick_task_config_form.fast_label() }}
          </div>
          <div class="field">
            <label for="{{ quick_task_config_form.fast_points.id }}">Punkte</label>
            {{ quick_task_config_form.fast_points() }}
          </div>
        </div>
        <div class="badge-setting-card">
          <div>
            <strong>Slot 2</strong>
            <p class="muted">Typische Alltagssache.</p>
          </div>
          <div class="field">
            {{ quick_task_config_form.normal_label.label }}
            {{ quick_task_config_form.normal_label() }}
          </div>
          <div class="field">
            <label for="{{ quick_task_config_form.normal_points.id }}">Punkte</label>
            {{ quick_task_config_form.normal_points() }}
          </div>
        </div>
        <div class="badge-setting-card">
          <div>
            <strong>Slot 3</strong>
            <p class="muted">Braucht etwas mehr Zeit oder Konzentration.</p>
          </div>
          <div class="field">
            {{ quick_task_config_form.medium_label.label }}
            {{ quick_task_config_form.medium_label() }}
          </div>
          <div class="field">
            <label for="{{ quick_task_config_form.medium_points.id }}">Punkte</label>
            {{ quick_task_config_form.medium_points() }}
          </div>
        </div>
        <div class="badge-setting-card">
          <div>
            <strong>Slot 4</strong>
            <p class="muted">Spürbarer Aufwand mit mehr Punkten.</p>
          </div>
          <div class="field">
            {{ quick_task_config_form.heavy_label.label }}
            {{ quick_task_config_form.heavy_label() }}
          </div>
          <div class="field">
            <label for="{{ quick_task_config_form.heavy_points.id }}">Punkte</label>
            {{ quick_task_config_form.heavy_points() }}
          </div>
        </div>
        <div class="badge-setting-card">
          <div>
            <strong>Slot 5</strong>
            <p class="muted">Extra große Aufgabe für echte Kraftakte.</p>
          </div>
          <div class="field">
            {{ quick_task_config_form.super_heavy_label.label }}
            {{ quick_task_config_form.super_heavy_label() }}
          </div>
          <div class="field">
            <label for="{{ quick_task_config_form.super_heavy_points.id }}">Punkte</label>
            {{ quick_task_config_form.super_heavy_points() }}
          </div>
        </div>
        <div class="field field--full">
          {{ quick_task_config_form.submit(class_='button button--secondary') }}
        </div>
      </form>
    </section>
  {% endif %}
{% endblock %}
