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


{% block page_title %}
    {% trans "Winners List" %}
{% endblock page_title %}


{% block details %}
<div class="container my-5">
    <!-- Main Header -->
    <div class="text-center mb-5">
        <h2 class="fw-bold" style="color: #f1c40f;">
            <i class="fas fa-trophy me-2" style="color: #27ae60;"></i>
            {% trans "Winners List" %}
        </h2>
        <p class="text-muted fs-5">
            {% trans "Celebrate our lucky winners and their victories!" %}
        </p>
    </div>

    <!-- Podium: Top 3 Winners -->
    {% if top_3 %}
    <div class="mb-5">
        <h3 class="text-center mb-3 fw-bold" style="color: #f1c40f;">
            <i class="fas fa-medal me-2"></i>
            {% trans "Top Winners Podium" %}
        </h3>
        <div class="d-flex justify-content-center gap-4">
            {% for user in top_3 %}
            <div class="card text-center border-0 shadow-sm" style="width: 12rem;">
                <div class="card-body">
                    {% if forloop.first %}
                        <!-- 1st Place -->
                        <i class="fas fa-award fa-3x" style="color: #f1c40f;"></i>
                        <p class="mt-2 fw-bold" style="color: #f1c40f;">{% trans "1st Place" %}</p>
                    {% elif forloop.counter == 2 %}
                        <!-- 2nd Place -->
                        <i class="fas fa-medal fa-3x" style="color: #95a5a6;"></i>
                        <p class="mt-2 fw-bold" style="color: #95a5a6;">{% trans "2nd Place" %}</p>
                    {% else %}
                        <!-- 3rd Place -->
                        <i class="fas fa-medal fa-3x" style="color: saddlebrown;"></i>
                        <p class="mt-2 fw-bold" style="color: saddlebrown;">{% trans "3rd Place" %}</p>
                    {% endif %}

                    <hr class="my-2">
                    <p class="mb-1">
                        <strong class="text-primary">{{ user.username }}</strong>
                    </p>
                    <p class="small text-muted">
                        {{ user.main_character_name|default:"No Main Character" }}
                    </p>
                    <p class="fw-bold" style="color: #f39c12;">
                        {{ user.total_prize|floatformat:2|intcomma }} ISK
                    </p>
                </div>
            </div>
            {% endfor %}
        </div>
    </div>
    {% endif %}

    <!-- General Winners Table -->
    {% if page_obj.object_list %}
    <div class="card shadow-sm border-0">
        <div class="card-header bg-dark text-white">
            <h4 class="mb-0">
                <i class="fas fa-list me-2"></i>
                {% trans "All Winners" %}
            </h4>
        </div>
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-striped table-hover align-middle mb-0">
                    <thead class="table-dark">
                        <tr>
                            <th scope="col">
                                <i class="fas fa-ticket-alt me-1"></i>
                                {% trans "Lottery Reference" %}
                            </th>
                            <th scope="col">
                                <i class="fas fa-portrait me-1"></i>
                                {% trans "Character" %}
                            </th>
                            <th scope="col">
                                <i class="fas fa-coins me-1"></i>
                                {% trans "Prize Amount (ISK)" %}
                            </th>
                            <th scope="col">
                                <i class="fas fa-calendar-check me-1"></i>
                                {% trans "Won At" %}
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for winner in page_obj.object_list %}
                        <tr>
                            <td>
                                <span class="badge bg-primary me-1">
                                    <i class="fas fa-ticket-alt"></i>
                                </span>
                                {{ winner.ticket.lottery.lottery_reference }}
                            </td>
                            <td>
                                <span class="badge bg-info text-light text-uppercase">
                                    {{ winner.character.character_name }}
                                </span>
                            </td>
                            <td>
                                <span class="text-warning fw-bold">
                                    {{ winner.prize_amount|floatformat:2|intcomma }} ISK
                                </span>
                            </td>
                            <td>
                                <i class="far fa-clock text-secondary me-1"></i>
                                {{ winner.won_at|date:"Y-m-d H:i" }}
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
        <!-- Pagination Footer -->
        <div class="card-footer bg-light">
            <nav aria-label="Page navigation">
                <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 }}" aria-label="Previous">
                            <span aria-hidden="true">&laquo;</span>
                        </a>
                    </li>
                    {% else %}
                    <li class="page-item disabled">
                        <span class="page-link" aria-hidden="true">&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 }}" aria-label="Next">
                            <span aria-hidden="true">&raquo;</span>
                        </a>
                    </li>
                    {% else %}
                    <li class="page-item disabled">
                        <span class="page-link" aria-hidden="true">&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 "No winners found." %}
    </div>
    {% endif %}
</div>
{% endblock details %}
