{% extends "base.html" %}
{% block title %}{% if mode == 'edit' %}Aufgabe bearbeiten{% else %}Aufgabe erstellen{% endif %} · Putzliga{% endblock %}
{% block page_title %}{% if mode == 'edit' %}Aufgabe bearbeiten{% else %}Aufgabe erstellen{% endif %}{% endblock %}
{% block content %}
  <section class="panel form-panel">
    <p class="eyebrow">{% if mode == 'edit' %}Bestehende Aufgabe anpassen{% else %}Neue Aufgabe und Vorlage{% endif %}</p>
    <h2>{% if mode == 'edit' %}Änderungen für {{ task.title }}{% else %}Neue Aufgabe anlegen{% endif %}</h2>
    <form method="post" class="form-grid form-grid--two">
      {{ form.hidden_tag() }}
      {% if mode == 'edit' %}
        <input type="hidden" name="next" value="{{ next_url }}">
      {% endif %}

      <div class="field field--full">
        {{ form.title.label }}
        {{ form.title(placeholder="Zum Beispiel: Küche wischen") }}
        {% for error in form.title.errors %}<small class="error">{{ error }}</small>{% endfor %}
      </div>

      <div class="field field--full">
        {{ form.description.label }}
        {{ form.description(rows="4", placeholder="Optional: kurze Hinweise zur Aufgabe") }}
        {% for error in form.description.errors %}<small class="error">{{ error }}</small>{% endfor %}
      </div>

      <div class="field">
        {{ form.default_points.label }}
        {{ form.default_points() }}
        {% for error in form.default_points.errors %}<small class="error">{{ error }}</small>{% endfor %}
      </div>

      <div class="field">
        {{ form.assigned_user_id.label }}
        {{ form.assigned_user_id() }}
        {% for error in form.assigned_user_id.errors %}<small class="error">{{ error }}</small>{% endfor %}
      </div>

      <div class="field">
        {{ form.assigned_user_secondary_id.label }}
        {{ form.assigned_user_secondary_id() }}
        <small class="muted">Wenn du hier noch jemanden auswählst, zählen die Punkte pro Person halbiert.</small>
        {% for error in form.assigned_user_secondary_id.errors %}<small class="error">{{ error }}</small>{% endfor %}
      </div>

      <div class="field">
        {{ form.due_date.label }}
        {{ form.due_date() }}
        {% for error in form.due_date.errors %}<small class="error">{{ error }}</small>{% endfor %}
      </div>

      <div class="field">
        {{ form.recurrence_interval_unit.label }}
        {{ form.recurrence_interval_unit() }}
      </div>

      <div class="field">
        {{ form.recurrence_interval_value.label }}
        {{ form.recurrence_interval_value() }}
        {% for error in form.recurrence_interval_value.errors %}<small class="error">{{ error }}</small>{% endfor %}
      </div>

      <label class="checkbox">
        {{ form.active() }}
        <span>Vorlage bleibt aktiv und erzeugt bei Wiederholung weitere Aufgaben</span>
      </label>

      <div class="form-actions field--full">
        {{ form.submit(class_='button') }}
        <a class="button button--ghost" href="{{ url_for('tasks.all_tasks') }}">Abbrechen</a>
        {% if mode == 'edit' %}
          <button
            type="submit"
            class="button button--ghost button--danger"
            formmethod="post"
            formaction="{{ url_for('tasks.delete', task_id=task.id) }}"
            onclick="return confirm('Diese Aufgabe wirklich löschen?');"
          >
            Aufgabe löschen
          </button>
        {% endif %}
      </div>
    </form>
  </section>
{% endblock %}
