{% extends "tesm_core/base.html" %}
{% from "tesm_core/macros.html" import empty_state, alert, pill %}

{% block page_title %}Papierkorb{% endblock %}
{% block page_sub %}{{ total }} Eintraege &middot; Aufbewahrung {{ retention_days }} Tage{% endblock %}

{% block content %}
{{ alert('Ansehen ist immer moeglich. Wiederherstellen und endgueltiges Loeschen erfordern eine
gueltige, aktivierte Lizenz. Abgelaufene Eintraege werden beim Aufruf dieser Seite entfernt.',
'info') }}

{% for section in sections %}
  <section class="card">
    <div class="card__header">
      <div class="flex-1">
        <div class="card__title">{{ icon(section.icon, size=17) }} {{ section.label }}
          {{ pill(section.entries | length, '') }}
        </div>
        {% if section.hint %}<div class="card__sub">{{ section.hint }}</div>{% endif %}
      </div>
      {% if section.entries and current_user.has('trash.delete') %}
        <form method="post" action="{{ url_for('trash.purge_all') }}" data-no-guard>
          <input type="hidden" name="{{ csrf_field_name }}" value="{{ csrf_token() }}">
          <input type="hidden" name="kind" value="{{ section.key }}">
          <button class="btn btn--sm btn--ghost danger-text" type="submit"
                  data-confirm="Alle {{ section.entries | length }} Eintraege unter {{ section.label }} endgueltig loeschen? Das laesst sich nicht rueckgaengig machen."
                  data-confirm-title="Endgueltig loeschen" data-confirm-ok="Endgueltig loeschen">
            Bereich leeren
          </button>
        </form>
      {% endif %}
    </div>
    {% if section.entries %}
      <div class="table-wrap">
        <table class="table table--compact">
          <thead><tr><th>Eintrag</th><th>Detail</th><th>Geloescht</th><th class="actions">Aktion</th></tr></thead>
          <tbody>
            {% for entry in section.entries %}
              <tr>
                <td class="fw-600">{{ entry.label }}</td>
                <td class="muted fs-sm">{{ entry.detail }}</td>
                <td class="fs-sm"><span data-relative-time="{{ entry.deleted_at }}">{{ entry.deleted_at | dt }}</span></td>
                <td class="actions">
                  {% if current_user.has('trash.edit') %}
                    <form method="post" style="display:inline" data-no-guard
                          action="{{ url_for('trash.restore', kind=section.key, ident=entry.id) }}">
                      <input type="hidden" name="{{ csrf_field_name }}" value="{{ csrf_token() }}">
                      <button class="btn btn--sm" type="submit">Wiederherstellen</button>
                    </form>
                  {% endif %}
                  {% if current_user.has('trash.delete') %}
                    <form method="post" style="display:inline" data-no-guard
                          action="{{ url_for('trash.purge', kind=section.key, ident=entry.id) }}">
                      <input type="hidden" name="{{ csrf_field_name }}" value="{{ csrf_token() }}">
                      <button class="btn btn--sm btn--ghost danger-text" type="submit"
                              data-confirm="{{ entry.label }} endgueltig loeschen?"
                              data-confirm-title="Endgueltig loeschen" data-confirm-ok="Loeschen">
                        Endgueltig
                      </button>
                    </form>
                  {% endif %}
                </td>
              </tr>
            {% endfor %}
          </tbody>
        </table>
      </div>
    {% else %}
      {{ empty_state('Nichts im Papierkorb', '', section.icon) }}
    {% endif %}
  </section>
{% endfor %}
{% endblock %}
