{% extends 'gakusei/layout.html' %}

{% block body %}

    <div class="container">

        <a href="{% url 'index' %}" class="mb-4 btn bg-success-subtle text-reset"><i class="fa-solid fa-angles-left"></i> Regresar al Index</a>
    
        <div class="card">
            <div class="card-body">
                
                <h1 class="card-title mb-4">Listado de Estudiantes</h1>
            
                <div class="d-flex d-md-block justify-content-between">
                    
                    <a href="{% url 'estudiante-create' %}"  class="mb-4 btn btn-lg bg-success-subtle text-reset"><i class="fa-solid fa-plus"></i> Registrar Estudiante</a>           
                    
                    <a href="{% url 'estudiante-filter' %}" class="mb-4 btn btn-lg bg-primary-subtle text-reset"><i class="fa-solid fa-magnifying-glass"></i> <span class="d-none d-md-inline">Buscar Registro</span></a>
                    
                    <div class="dropdown mb-4">
                        <button class="btn btn-lg btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-expanded="false">
                            Filtrar por Estado
                        </button>
                        <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                            <li><a class="dropdown-item" href="{% url 'estudiante' %}">Todos</a></li>
                            <li><a class="dropdown-item text-success" href="{% url 'estudiante' %}?status=Activo">Activos</a></li>
                            <li><a class="dropdown-item text-warning" href="{% url 'estudiante' %}?status=Pausado">Pausados</a></li>
                            <li><a class="dropdown-item text-danger" href="{% url 'estudiante' %}?status=Retirado">Retirados</a></li>
                        </ul>
                    </div>
                    
                </div>
            
                <div class="table-responsive">
                    <table class="table table-striped table-hover table-bordered">
                        <thead class="table-primary">
                            <th>Cédula</th>
                            <th>Nombre Completo</th>
                            <th>Email</th>
                            <th>Telefono</th>
                            <th>Status</th>
                            <th></th>
                        </thead>
                        <tbody>
                            {% for estudiante in object_list %}
                            <tr>
                                <td>{{estudiante.cedula}}</td>
                                <td>{{estudiante.full_name}}</td>
                                <td>{{estudiante.personal_data.personal_email}}</td>
                                <td>{{estudiante.personal_data.telefono}}</td>
                                <td class="{% if estudiante.status|lower == 'activo' %}text-success{% elif estudiante.status|lower == 'pausado' %}text-warning{% elif estudiante.status|lower == 'retirado' %}text-danger{% endif %}">{{estudiante.status}}</td>
                                <td class="text-center align-middle">
                                    <a href="{% url 'estudiante-detail' estudiante.id %}"><i class="fs-4 fa-solid fa-eye"></i></a>
                                    <a href="{% url 'estudiante-delete' estudiante.id %}" title="Borrar Estudiante" class="text-danger ms-3">
                                        <i class="fs-4 fa-solid fa-trash"></i>
                                    </a>
                                </td>
                            </tr>
                            {% empty %}
                            <tr>
                                <td colspan="6" class="text-center fw-bold fst-italic">Sin Registros</td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>

            </div>

            <div class="card-footer text-body-secondary">
                <ul class="pagination justify-content-center mb-0">
                    
                    {% if page_obj.has_previous %}
                        <li class="page-item"><a class="page-link" href="?page=1">&laquo;</a></li>
                        <li class="page-item"><a class="page-link" href="?page={{ page_obj.previous_page_number }}">Atrás</a></li>
                    {% endif %}
            
                        <li class="page-item"><span class="page-link">{{ page_obj.number }} de {{ page_obj.paginator.num_pages }}</span></li>
            
            
                    {% if page_obj.has_next %}
                        <li class="page-item"><a class="page-link" href="?page={{ page_obj.next_page_number }}">Siguiente</a></li>
                        <li class="page-item"><a class="page-link" href="?page={{ page_obj.paginator.num_pages }}">&raquo;</a></li>
                    {% endif %}
                    
                </ul>
            </div>
        </div>

    </div>

    
{% endblock %}
