{% extends "admin_base.html" %}
{% block admin_content %}
<div class="admin-toolbar">
    <h2>Trash</h2>
    <span class="admin-count">{{ pagination.total }} soft-deleted</span>
</div>

<nav class="admin-tabs" data-overflow-tabs aria-label="Trash categories">
    <div class="overflow-tabs-strip">
        {% for tab in tables %}
        <a href="/admin/trash?table={{ tab['key'] }}" class="admin-tab {% if tab['active'] %}active{% endif %}" data-menu-icon="{{ tab['icon'] }}" data-menu-label="{{ tab['label'] }} ({{ tab['count'] }})">
            <span class="icon">{{ tab['icon'] }}</span> {{ tab['label'] }} <span class="admin-tab-count">{{ tab['count'] }}</span>
        </a>
        {% endfor %}
    </div>
    <button type="button" class="admin-tab overflow-tabs-more" aria-haspopup="menu" aria-label="More tabs" hidden><span class="icon">&#x22EF;</span> More</button>
</nav>

<table class="admin-table">
    <caption class="sr-only">Soft-deleted items with restore and purge actions</caption>
    <thead>
        <tr>
            <th scope="col">Item</th>
            <th scope="col">Removed</th>
            <th scope="col">Removed by</th>
            <th scope="col" class="admin-table-actions">Actions</th>
        </tr>
    </thead>
    <tbody>
        {% for item in items %}
        <tr>
            <td>
                {% if item['target_url'] %}
                <a href="{{ item['target_url'] }}">{{ item['label'] }}</a>
                {% else %}
                {{ item['label'] }}
                {% endif %}
            </td>
            <td>{{ local_dt(item['deleted_at']) }}</td>
            <td>{{ item['deleted_by'] or 'system' }}</td>
            <td class="admin-table-actions">
                <form method="POST" action="/admin/trash/{{ item['table'] }}/{{ item['uid'] }}/restore" class="admin-inline-form">
                    <button type="submit" class="admin-btn admin-btn-sm" aria-label="Restore {{ item['label'] }}"><span class="icon">&#x267B;&#xFE0F;</span> Restore</button>
                </form>
                <form method="POST" action="/admin/trash/{{ item['table'] }}/{{ item['uid'] }}/purge" class="admin-inline-form">
                    <button type="submit" class="admin-btn admin-btn-sm" data-confirm-danger data-confirm="Permanently delete this item and everything removed with it? This cannot be undone." aria-label="Permanently delete {{ item['label'] }}"><span class="icon">&#x1F5D1;&#xFE0F;</span> Purge</button>
                </form>
            </td>
        </tr>
        {% else %}
        <tr>
            <td colspan="4" class="empty-state">Trash is empty.</td>
        </tr>
        {% endfor %}
    </tbody>
</table>

{% include "_pagination.html" %}
{% endblock %}
