{% extends 'base.html' %}

{% block titulo %}Directores{% endblock %}

{% block vertical %} {% include 'partes/vertical.html' %} {% endblock %}
{% block horizontal %} {% include 'partes/horizontal.html' %} {% endblock %}

{% block seccion %}
<div class="d-flex align-items-left align-items-md-center flex-column flex-md-row pt-2 pb-5">
    <div>
        <h3 class="fw-bold mb-2">Directores</h3>
        <h6 class="op-7 mb-1">Servicio de Transporte del Ejército Bolivariano</h6>
    </div>
    <div class="ms-md-auto py-1">
        <a href="{% url 'crear_director' %}" class="btn btn-primary fw-bold ">Crear Directores</a>
    </div>
</div>
{% endblock %}

{% block contenido %}
<div class="card shadow-sm rounded-3 border-0">
    <div class="card-header bg-primary py-2 rounded-top">
        <h5 class="card-title mb-0 text-white fw-bold"><i class="fas fa-address-card me-1"></i>Lista de Directores</h5>
    </div>
    <div class="card-body p-2">
        <div class="table-responsive">
            <table id="directoresTable" class="table table-sm table-striped">
                <thead style="background-color: #f8f9fa;">
                    <tr>
                        <th class="text-center py-1">N°</th>
                        <th class="py-1">Grado</th>
                        <th class="py-1">Nombres y Apellidos</th>
                        <th class="py-1">Cargo</th>
                        <th class="text-center py-1">Acciones</th>
                    </tr>
                </thead>
                <tbody>
                    {% for director in directores %}
                    <tr>
                        <td class="text-center py-1 fw-bold">{{ forloop.counter }}</td>
                        <td class="py-1">{{ director.grado|default:"-" }}</td>
                        <td class="py-1">{{ director.nombres|default:"-" }}</td>
                        <td class="py-1">{{ director.cargos|default:"-" }}</td>
                        <td class="text-center py-1">
                            <div class="d-flex justify-content-center gap-1">
                                <a href="{% url 'editar_director' director.pk %}" class="btn btn-primary btn-xs async-link" data-url="{% url 'editar_director' director.pk %}" title="Editar">
                                    <i class="fas fa-pen fa-xs"></i>
                                </a>
                                <form action="{% url 'eliminar_director' director.pk %}" method="post" class="d-inline delete-form">
                                    {% csrf_token %}
                                    <button type="submit" class="btn btn-danger btn-xs" title="Eliminar">
                                        <i class="fas fa-trash fa-xs"></i>
                                    </button>
                                </form>
                            </div>
                        </td>
                    </tr>
                    {% empty %}
                    <tr>
                        <td colspan="10" class="text-center py-1">No hay directores registrados</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}

{% block pie %} {% include 'partes/pie.html' %} {% endblock %}


{% block js %}
<script>
    $(document).ready(function() {
        $('#directoresTable').DataTable({
            "language": {
                "decimal": "",
                "emptyTable": "No hay datos disponibles",
                "info": "Mostrando _START_ a _END_ de _TOTAL_ registros",
                "infoEmpty": "Mostrando 0 a 0 de 0 registros",
                "infoFiltered": "(filtrado de _MAX_ registros totales)",
                "lengthMenu": "Mostrar _MENU_ registros",
                "loadingRecords": "Cargando...",
                "processing": "Procesando...",
                "search": "Buscar:",
                "zeroRecords": "No se encontraron registros",
                "paginate": {
                    "first": "Primero",
                    "last": "Último",
                    "next": "Siguiente",
                    "previous": "Anterior"
                }
            },
            "pageLength": 10,
            "searching": true,
            "paging": true,
            "ordering": false,
            "info": false,
            "lengthChange": true
        });
    });
</script>



{% endblock %}