{# fortunaisk/templates/fortunaisk/resolved_anomalies_list.html #}
{% extends "fortunaisk/base.html" %}
{% load i18n humanize static %}

{% block page_title %}
    {% trans "Resolved Anomalies" %}
{% endblock page_title %}

{% block details %}
<div class="container my-5">
    <!-- Header -->
    <div class="text-center mb-5">
        <h2 class="fw-bold" style="color: #27ae60;">
            <i class="fas fa-check-circle me-2" style="color: #2ecc71;"></i>
            {% trans "Resolved Anomalies" %}
        </h2>
        <p class="text-muted fs-5">
            {% trans "Review all anomalies that have been marked as solved." %}
        </p>
    </div>

    {% if page_obj.object_list %}
    <div class="card shadow-sm border-0">
        <div class="card-header bg-success text-white">
            <h5 class="mb-0">
                <i class="fas fa-list-alt me-2"></i>
                {% trans "List of Resolved Anomalies" %}
            </h5>
        </div>
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-bordered table-hover align-middle mb-0">
                    <thead class="table-dark">
                        <tr>
                            <th>{% trans "Lottery Ref." %}</th>
                            <th>{% trans "User" %}</th>
                            <th>{% trans "Character" %}</th>
                            <th>{% trans "Reason" %}</th>
                            <th>{% trans "Amount (ISK)" %}</th>
                            <th>{% trans "Payment Date" %}</th>
                            <th>{% trans "Recorded At" %}</th>
                            <th>{% trans "Solved At" %}</th>
                            <th>{% trans "Solved By" %}</th>
                            <th>{% trans "Detail" %}</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for anomaly in page_obj.object_list %}
                        <tr>
                            <td>
                                {% if anomaly.lottery %}
                                    {{ anomaly.lottery.lottery_reference }}
                                {% else %}
                                    <span class="text-muted">N/A</span>
                                {% endif %}
                            </td>
                            <td>
                                {% if anomaly.user %}
                                    {{ anomaly.user.username }}
                                {% else %}
                                    <span class="text-muted">N/A</span>
                                {% endif %}
                            </td>
                            <td>
                                {% if anomaly.character %}
                                    {{ anomaly.character.character_name }}
                                {% else %}
                                    <span class="text-muted">N/A</span>
                                {% endif %}
                            </td>
                            <td>{{ anomaly.reason }}</td>
                            <td>{{ anomaly.amount|floatformat:2|intcomma }}</td>
                            <td>{{ anomaly.payment_date|date:"Y-m-d H:i" }}</td>
                            <td>{{ anomaly.recorded_at|date:"Y-m-d H:i" }}</td>
                            <td>{{ anomaly.solved_at|date:"Y-m-d H:i" }}</td>
                            <td>
                                {% if anomaly.solved_by %}
                                    {{ anomaly.solved_by.username }}
                                {% else %}
                                    <span class="text-muted">—</span>
                                {% endif %}
                            </td>
                            <td>
                                {% if anomaly.detail %}
                                    {{ anomaly.detail|linebreaksbr }}
                                {% else %}
                                    <span class="text-muted">—</span>
                                {% endif %}
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
        <div class="card-footer bg-light">
            <nav aria-label="Page navigation" class="my-3">
                <ul class="pagination justify-content-center mb-0">
                    {% if page_obj.has_previous %}
                        <li class="page-item">
                            <a class="page-link" href="?page={{ page_obj.previous_page_number }}">
                                &laquo;
                            </a>
                        </li>
                    {% else %}
                        <li class="page-item disabled">
                            <span class="page-link">&laquo;</span>
                        </li>
                    {% endif %}

                    {% for num in page_obj.paginator.page_range %}
                        {% if page_obj.number == num %}
                            <li class="page-item active"><span class="page-link">{{ num }}</span></li>
                        {% else %}
                            <li class="page-item">
                                <a class="page-link" href="?page={{ num }}">{{ num }}</a>
                            </li>
                        {% endif %}
                    {% endfor %}

                    {% if page_obj.has_next %}
                        <li class="page-item">
                            <a class="page-link" href="?page={{ page_obj.next_page_number }}">
                                &raquo;
                            </a>
                        </li>
                    {% else %}
                        <li class="page-item disabled">
                            <span class="page-link">&raquo;</span>
                        </li>
                    {% endif %}
                </ul>
            </nav>
        </div>
    </div>
    {% else %}
    <div class="alert alert-info text-center">
        <i class="fas fa-info-circle me-2"></i>
        {% trans "There are no resolved anomalies yet." %}
    </div>
    {% endif %}
</div>
{% endblock details %}
