{% extends 'base.html' %}

{% block titulo %}Detalles de la Unidad{% endblock %}

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

{% block css %}
<style>
    #administrativoTable th, #tacticoTable th, 
    #administrativoTable td, #tacticoTable td {
        vertical-align: middle;
        max-width: 150px;
        word-wrap: break-word;
        white-space: normal;
    }
</style>
{% 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-1">Información de Vehículos</h3>
        <h6 class="op-7 mb-0">Servicio de Transporte del Ejército Bolivariano</h6>
    </div>
    <div class="ms-md-auto py-1">
        <a href="{% url 'unidad_list' %}" class="btn btn-dark fw-bold ">Atrás</a>
    </div>
</div>
{% endblock %}

{% block contenido %}
<div class="card card-stats card-round mb-2">
    <div class="card-header bg-primary py-1 rounded-top">
        <div class="d-flex justify-content-between align-items-center">
            <h4 class="card-title mb-0 text-white fw-bold ">Vehículos Administrativos</h4>
            <a href="{% url 'pdf_admin' unidad.pk %}" class="btn btn-primary btn-sm">
                <i class="fas fa-file-pdf me-1"></i>Exportar PDF
            </a>
        </div>
    </div>
    <div class="card-body p-1">
        <div class="table-responsive">
            <table id="administrativoTable" class="table table-sm table-striped">
                <thead style="background-color: #f8f9fa;">
                    <tr>
                        <th class="text-center py-0 px-1">N°</th>
                        <th class="py-0 px-1">Placa Militar</th>
                        <th class="py-0 px-1">Clase</th>
                        <th class="py-0 px-1">Tipo</th>
                        <th class="py-0 px-1">Marca</th>
                        <th class="py-0 px-1">Modelo</th>
                        <th class="py-0 px-1">Serial de Carrocería</th>
                        <th class="py-0 px-1">Fecha de Asignación</th>
                    </tr>
                </thead>
                <tbody>
                    {% for administrativo in administrativo %}
                    <tr>
                        <td class="text-center py-0 px-1">{{ forloop.counter }}</td>
                        <td class="py-0 px-1">{{ administrativo.vehiculo.placa_militar|default:"-" }}</td>
                        <td class="py-0 px-1">{{ administrativo.vehiculo.clase|default:"-" }}</td>
                        <td class="py-0 px-1">{{ administrativo.vehiculo.tipo|default:"-" }}</td>
                        <td class="py-0 px-1">{{ administrativo.vehiculo.marca|default:"-" }}</td>
                        <td class="py-0 px-1">{{ administrativo.vehiculo.modelo|default:"-" }}</td>
                        <td class="py-0 px-1">{{ administrativo.vehiculo.serial_carroceria|default:"-" }}</td>
                        <td class="py-0 px-1">{{ administrativo.fecha_creacion|date:"d-m-Y"|default:"-" }}</td>
                        <td class="py-0 px-1">
                            <form action="{% url 'eliminar_asignacion_admin' administrativo.pk %}" method="post">
                                {% csrf_token %}
                                <button type="submit" class="btn btn-danger btn-sm">Eliminar</button>
                            </form>
                        </td>
                    </tr>
                    {% empty %}
                    <tr>
                        <td colspan="8" class="text-center py-0 px-1">No hay vehículos administrativos asignados</td>
                    </tr>

                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>

<div class="card card-stats card-round">
    <div class="card-header bg-primary py-1 rounded-top">
        <div class="d-flex justify-content-between align-items-center">
            <h4 class="card-title mb-0 text-white fw-bold">Vehículos Tácticos</h4>
            <a href="{% url 'pdf_tactico' unidad.pk %}" class="btn btn-primary ">
                <i class="fas fa-file-pdf me-1"></i>Exportar PDF
            </a>
        </div>
    </div>
    <div class="card-body p-1">
        <div class="table-responsive">
            <table id="tacticoTable" class="table table-sm table-striped fs-6">
                <thead style="background-color: #f8f9fa;">
                    <tr>
                        <th class="text-center py-0 px-1">N°</th>
                        <th class="py-0 px-1">Tipo de Vehículo</th>
                        <th class="py-0 px-1">Modelo</th>
                        <th class="py-0 px-1">Marca</th>
                        <th class="py-0 px-1">Serial Chasis</th>
                        <th class="py-0 px-1">Serial Motor</th>
                        <th class="py-0 px-1">Fecha de Asignación</th>
                    </tr>
                </thead>
                <tbody>
                    {% for tactico in tactico %}
                    <tr>
                        <td class="text-center py-0 px-1">{{ forloop.counter }}</td>
                        <td class="py-0 px-1">{{ tactico.vehiculo.tipo_vehiculo|default:"-" }}</td>
                        <td class="py-0 px-1">{{ tactico.vehiculo.modelo|default:"-" }}</td>
                        <td class="py-0 px-1">{{ tactico.vehiculo.marca|default:"-" }}</td>
                        <td class="py-0 px-1">{{ tactico.vehiculo.serial_chasis|default:"-" }}</td>
                        <td class="py-0 px-1">{{ tactico.vehiculo.serial_motor|default:"-" }}</td>
                        <td class="py-0 px-1">{{ tactico.fecha_creacion|date:"d-m-Y"|default:"-" }}</td>

                        <td>
                            <form action="{% url 'eliminar_asignacion_tactica' tactico.pk %}" method="post">
                                {% csrf_token %}
                                <button type="submit" class="btn btn-danger btn-sm">Eliminar</button>
                            </form>
                        </td>
                    </tr>
                    {% empty %}
                    <tr>
                        <td colspan="7" class="text-center py-0 px-1">No hay vehículos tácticos asignados</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}

{% block js %}


<script>
$(document).ready(function() {
    $('#administrativoTable').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
    });

    $('#tacticoTable').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 %}