{% extends "base.html" %}

{% block title %}TIC Log - Admin{% endblock %}

{% block content %}
<div class="bbs-header">
    <h1><i class="bi bi-file-earmark-arrow-down"></i> TIC Log</h1>
    <p>Inbound FidoNet file-echo manifests.</p>
</div>

<div class="card">
    <div class="card-body p-0">
        <table class="table table-sm table-hover mb-0">
            <thead><tr>
                <th>Received</th><th>Status</th><th>Area</th><th>File</th>
                <th>Size</th><th>From</th><th>Error</th>
            </tr></thead>
            <tbody>
            {% for t in pagination.items %}
                <tr>
                    <td><code>{{ t.received_at.strftime('%Y-%m-%d %H:%M') }}</code></td>
                    <td>
                        {% if t.status == 'filed' %}<span class="badge bg-success">filed</span>
                        {% elif t.status == 'error' %}<span class="badge bg-danger">error</span>
                        {% elif t.status == 'pending' %}<span class="badge bg-secondary">pending</span>
                        {% else %}<span class="badge bg-warning text-dark">{{ t.status }}</span>{% endif %}
                    </td>
                    <td><code>{{ t.area_tag or '?' }}</code></td>
                    <td><a href="{{ url_for('admin.tic_detail', tic_id=t.id) }}">{{ t.filename or '?' }}</a></td>
                    <td>{{ t.size_bytes or 0 }}</td>
                    <td><code>{{ t.from_address or '' }}</code></td>
                    <td><small class="text-danger">{{ t.error_message or '' }}</small></td>
                </tr>
            {% else %}
                <tr><td colspan="7" class="text-muted text-center p-3">No TICs received yet.</td></tr>
            {% endfor %}
            </tbody>
        </table>
    </div>
</div>

{% if pagination.pages > 1 %}
<nav class="mt-3">
    <ul class="pagination">
        {% if pagination.has_prev %}<li class="page-item"><a class="page-link" href="?page={{ pagination.prev_num }}">Prev</a></li>{% endif %}
        <li class="page-item disabled"><span class="page-link">{{ pagination.page }}/{{ pagination.pages }}</span></li>
        {% if pagination.has_next %}<li class="page-item"><a class="page-link" href="?page={{ pagination.next_num }}">Next</a></li>{% endif %}
    </ul>
</nav>
{% endif %}
{% endblock %}
