{% extends 'main.html' %}
{% load static %}
{% block content %}

<!--context['bap_club'] + bap_leaderboard context_object -->

<div class="container">
    <h3>{{ bap_club.name }}</h3>
    <div class="card mb-4">
        <div class="card-header d-flex justify-content-between align-items-center">
            <h4>BAP Leaderboard</h4>
            <span>Total: {{ page_obj.paginator.count }} BAP Participants found</span>
        </div>
        <div class="card-body">
            {% if bap_leaderboard %}
                <div class="table-responsive">
                    <table class="table table-striped table-hover">                    
                        <thead>
                            <tr>
                                <th>Aquarist</th>
                                <th>Fishroom</th> 
                                <th style='text-align:center'>Total Species</th> 
                                <th style='text-align:center'>CARES Species</th> 
                                <th style='text-align:center'>Total Points</th>                                 
                            </tr>
                        </thead>
                        <tbody>
                            {% for bap_participant in bap_leaderboard %}
                                <tr>
                                    <td>{{ bap_participant.aquarist.first_name }} {{ bap_participant.aquarist.last_name }}</td>
                                    <td><a href="{% url 'aquarist' bap_participant.aquarist.id %}">{{bap_participant.aquarist.get_display_name}} </td>  
                                    <td style='text-align:center'>{{bap_participant.species_count}}</td>  
                                    <td style='text-align:center'>{{bap_participant.cares_species_count}}</td>  
                                    <td style='text-align:center'>{{bap_participant.points}}</td>  
    
                            {% endfor %}
                        </tbody>
                    </table>
                </div>

                <!-- Pagination -->
                {% if is_paginated %}
                <nav aria-label="Page navigation">
                    <ul class="pagination justify-content-center">
                        {% if page_obj.has_previous %}
                            <li class="page-item">
                                <a class="page-link" href="?page=1{% if selected_category %}&category={{ selected_category }}{% endif %}{% if selected_region %}&global_region={{ selected_region }}{% endif %}{% if query_text %}&q={{ query_text }}{% endif %}" aria-label="First">
                                    <span aria-hidden="true">&laquo;&laquo;</span>
                                </a>
                            </li>
                            <li class="page-item">
                                <a class="page-link" href="?page={{ page_obj.previous_page_number }}{% if selected_category %}&category={{ selected_category }}{% endif %}{% if selected_region %}&global_region={{ selected_region }}{% endif %}{% if query_text %}&q={{ query_text }}{% endif %}" aria-label="Previous">
                                    <span aria-hidden="true">&laquo;</span>
                                </a>
                            </li>
                        {% endif %}
                        
                        {# Show current page and neighboring pages #}
                        {% for i in page_obj.paginator.page_range %}
                            {% if page_obj.number == i %}
                                <li class="page-item active"><span class="page-link">{{ i }}</span></li>
                            {% elif i > page_obj.number|add:'-3' and i < page_obj.number|add:'3' %}
                                <li class="page-item">
                                    <a class="page-link" href="?page={{ i }}{% if selected_category %}&category={{ selected_category }}{% endif %}{% if selected_region %}&global_region={{ selected_region }}{% endif %}{% if query_text %}&q={{ query_text }}{% endif %}">{{ i }}</a>
                                </li>
                            {% endif %}
                        {% endfor %}
                        
                        {% if page_obj.has_next %}
                            <li class="page-item">
                                <a class="page-link" href="?page={{ page_obj.next_page_number }}{% if selected_category %}&category={{ selected_category }}{% endif %}{% if selected_region %}&global_region={{ selected_region }}{% endif %}{% if query_text %}&q={{ query_text }}{% endif %}" aria-label="Next">
                                    <span aria-hidden="true">&raquo;</span>
                                </a>
                            </li>
                            <li class="page-item">
                                <a class="page-link" href="?page={{ page_obj.paginator.num_pages }}{% if selected_category %}&category={{ selected_category }}{% endif %}{% if selected_region %}&global_region={{ selected_region }}{% endif %}{% if query_text %}&q={{ query_text }}{% endif %}" aria-label="Last">
                                    <span aria-hidden="true">&raquo;&raquo;</span>
                                </a>
                            </li>
                        {% endif %}
                    </ul>
                </nav>
                {% endif %}
            {% else %}
                <p>None</p>
            {% endif %}
        </div>
    </div>
    <div>
        <p><a class="btn btn-secondary" href="{% url 'bapSubmissions' bap_club.id %}" role="button">BAP Submissions</a></p>
    </div>
</div>

{% endblock content %}

