{% extends 'base.html' %}
{% load static %}

{% block title %}SMS Messages - Rapha-Bethel BNPS{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1 class="h3 mb-0 text-gray-800">SMS Messages</h1>
        <a href="/admin/communication/smsmessage/add/" class="btn btn-primary">
            <i class="fas fa-plus"></i> Compose SMS
        </a>
    </div>

    <div class="card shadow">
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>Type</th>
                            <th>Message</th>
                            <th>Recipients</th>
                            <th>Status</th>
                            <th>Sent Time</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for sms in messages %}
                        <tr>
                            <td>{{ sms.get_message_type_display }}</td>
                            <td>{{ sms.message|truncatechars:50 }}</td>
                            <td>{{ sms.phone_numbers|length }}</td>
                            <td>
                                <span class="badge bg-{% if sms.status == 'sent' %}success{% elif sms.status == 'failed' %}danger{% else %}secondary{% endif %}">
                                    {{ sms.get_status_display }}
                                </span>
                            </td>
                            <td>{{ sms.sent_time|default:"Not sent" }}</td>
                        </tr>
                        {% empty %}
                        <tr>
                            <td colspan="5" class="text-center">No SMS messages</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
{% endblock %}