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

{% block content %}
<div class="container py-5">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2>{% trans "Financial History" %}</h2>
        <a href="{% url 'dashboard' %}" class="btn btn-outline-secondary btn-sm">
            <i class="fas fa-arrow-left"></i> {% trans "Back to Dashboard" %}
        </a>
    </div>

    <div class="card shadow-sm border-0">
        <div class="card-body">
            {% if transactions %}
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead class="table-light">
                        <tr>
                            <th>{% trans "Receipt #" %}</th>
                            <th>{% trans "Date" %}</th>
                            <th>{% trans "Description" %}</th>
                            <th>{% trans "Type" %}</th>
                            <th>{% trans "Amount" %}</th>
                            <th>{% trans "Status" %}</th>
                            <th>{% trans "Action" %}</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for transaction in transactions %}
                        <tr>
                            <td><code>{{ transaction.receipt_number }}</code></td>
                            <td>{{ transaction.created_at|date:"Y-m-d H:i" }}</td>
                            <td>{{ transaction.description }}</td>
                            <td>
                                {% if transaction.transaction_type == 'PAYMENT' %}
                                <span class="badge bg-success">{% trans "Payment" %}</span>
                                {% else %}
                                <span class="badge bg-warning text-dark">{% trans "Refund" %}</span>
                                {% endif %}
                            </td>
                            <td><strong>{{ transaction.amount }}</strong></td>
                            <td>
                                <span class="badge {% if transaction.status == 'COMPLETED' %}bg-info{% elif transaction.status == 'PENDING' %}bg-secondary{% else %}bg-danger{% endif %}">
                                    {{ transaction.get_status_display }}
                                </span>
                            </td>
                            <td>
                                <a href="{% url 'transaction_receipt' transaction.receipt_number %}" class="btn btn-sm btn-outline-primary" target="_blank">
                                    <i class="fas fa-file-invoice-dollar"></i> {% trans "Receipt" %}
                                </a>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
            {% else %}
            <div class="text-center py-5">
                <i class="fas fa-receipt fa-3x text-muted mb-3"></i>
                <p class="text-muted">{% trans "No transactions found." %}</p>
            </div>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}
