{% extends 'base.html' %}
{% block title %}Payments{% endblock %}

{% block content %}
<div class="container mt-3">

    <h4 class="mb-3"><i class="bi bi-wallet2"></i> My Payments</h4>

    <!-- INVOICES -->
    <div class="card shadow-sm mb-4">
        <div class="card-body">
            <h6>Invoices</h6>

            <div class="table-responsive">
                <table class="table table-sm align-middle">
                    <thead>
                        <tr>
                            <th>Amount</th>
                            <th>Due Date</th>
                            <th>Status</th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for invoice in invoices %}
                        <tr>
                            <td>KES {{ invoice.amount }}</td>
                            <td>{{ invoice.due_date }}</td>
                            <td>
                                {% if invoice.status == 'paid' %}
                                    <span class="badge bg-success">Paid</span>
                                {% elif invoice.status == 'partial' %}
                                    <span class="badge bg-warning text-dark">Partial</span>
                                {% else %}
                                    <span class="badge bg-danger">Pending</span>
                                {% endif %}
                            </td>
                            <td>
                                <a href="{% url 'invoice_detail' invoice.id %}" class="btn btn-outline-dark btn-sm">
                                    View
                                </a>
                            </td>
                        </tr>
                        {% empty %}
                        <tr><td colspan="4">No invoices found</td></tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>

        </div>
    </div>

    <!-- PAYMENTS -->
    <div class="card shadow-sm">
        <div class="card-body">
            <h6>Payment History</h6>

            <ul class="list-group">
                {% for payment in payments %}
                <li class="list-group-item d-flex justify-content-between align-items-center">
                    <span>KES {{ payment.amount }}</span>
                    <small class="text-muted">{{ payment.created_at }}</small>
                </li>
                {% empty %}
                <li class="list-group-item">No payments yet</li>
                {% endfor %}
            </ul>
        </div>
    </div>

</div>
{% endblock %}