{% extends "base.html" %}
{% block content %}

<div class="container-fluid mt-4">

    <div class="d-flex justify-content-between align-items-center mb-3">
        <h4>Tenant Applications</h4>
    </div>

    <div class="card shadow-sm">
        <div class="card-body">

            {% if applications %}
            <div class="table-responsive">
                <table class="table table-hover align-middle">

                    <thead>
                        <tr>
                            <th>#</th>
                            <th>Tenant</th>
                            <th>ID Number</th>
                            <th>Phone</th>
                            <th>Status</th>
                            <th>Date</th>
                            <th>Actions</th>
                        </tr>
                    </thead>

                    <tbody>
                        {% for app in applications %}
                        <tr>
                            <td>{{ forloop.counter }}</td>

                            <td>{{ app.user.get_full_name }}</td>

                            <td>{{ app.id_number }}</td>

                            <td>
                                {{ app.user.phone_number|default:"-" }}
                            </td>

                            <td>
                                {% if app.status == "pending" %}
                                    <span class="badge bg-warning">Pending</span>
                                {% elif app.status == "approved" %}
                                    <span class="badge bg-success">Approved</span>
                                {% else %}
                                    <span class="badge bg-danger">Rejected</span>
                                {% endif %}
                            </td>

                            <td>{{ app.submitted_at|date:"Y-m-d" }}</td>

                            <td>
                                {% if app.status == "pending" %}
                                    <a href="{% url 'approve_tenant' app.id %}"
                                       class="btn btn-sm btn-success">
                                        Approve
                                    </a>

                                    <a href="{% url 'reject_tenant' app.id %}"
                                       class="btn btn-sm btn-danger">
                                        Reject
                                    </a>
                                {% else %}
                                    <span class="text-muted">No action</span>
                                {% endif %}
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>

                </table>
            </div>
            {% else %}
                <div class="text-center py-4">
                    <p>No applications found.</p>
                </div>
            {% endif %}

        </div>
    </div>

</div>

{% endblock %}