{% extends "base.html" %}
{% block title %}Sent Messages - {{ config.BBS_NAME }}{% endblock %}
{% block content %}
<div class="bbs-header">
    <h1><i class="bi bi-send"></i> Sent Messages</h1>
</div>
<div class="d-flex justify-content-between mb-3">
    <a href="{{ url_for('pm.inbox') }}" class="btn btn-primary"><i class="bi bi-inbox"></i> Inbox</a>
    <a href="{{ url_for('pm.compose') }}" class="btn btn-primary"><i class="bi bi-pencil"></i> Compose</a>
</div>
<div class="card">
    <div class="card-body p-0">
        <table class="table mb-0">
            <thead><tr><th>To</th><th>Subject</th><th>Date</th><th>Read</th><th>Actions</th></tr></thead>
            <tbody>
                {% for msg in messages %}
                <tr>
                    <td>{{ msg.recipient.username }}</td>
                    <td><a href="{{ url_for('pm.read', message_id=msg.id) }}">{{ msg.subject }}</a></td>
                    <td>{{ msg.created_at|eastern('%Y-%m-%d %H:%M') }}</td>
                    <td>{% if msg.read_at %}<i class="bi bi-check-circle text-success"></i>{% else %}<i class="bi bi-clock"></i>{% endif %}</td>
                    <td>
                        <form method="post" action="{{ url_for('pm.delete', message_id=msg.id) }}" class="d-inline">
                            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                            <button type="submit" class="btn btn-sm btn-danger"><i class="bi bi-trash"></i></button>
                        </form>
                    </td>
                </tr>
                {% else %}
                <tr><td colspan="5" class="text-center">No sent messages.</td></tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
</div>

{% if pagination and pagination.pages > 1 %}
<nav aria-label="Sent messages pages" class="mt-3">
    <ul class="pagination justify-content-center">
        {% if pagination.has_prev %}
        <li class="page-item"><a class="page-link" href="{{ url_for('pm.sent', page=pagination.prev_num) }}">‹ Prev</a></li>
        {% else %}
        <li class="page-item disabled"><span class="page-link">‹ Prev</span></li>
        {% endif %}
        {% for p in pagination.iter_pages() %}
            {% if p %}
            <li class="page-item {{ 'active' if p == pagination.page else '' }}">
                <a class="page-link" href="{{ url_for('pm.sent', page=p) }}">{{ p }}</a>
            </li>
            {% else %}
            <li class="page-item disabled"><span class="page-link">…</span></li>
            {% endif %}
        {% endfor %}
        {% if pagination.has_next %}
        <li class="page-item"><a class="page-link" href="{{ url_for('pm.sent', page=pagination.next_num) }}">Next ›</a></li>
        {% else %}
        <li class="page-item disabled"><span class="page-link">Next ›</span></li>
        {% endif %}
    </ul>
    <p class="text-center text-muted small">Page {{ pagination.page }} of {{ pagination.pages }} — {{ pagination.total }} message{{ '' if pagination.total == 1 else 's' }} total</p>
</nav>
{% endif %}
{% endblock %}
