{% extends 'base.html' %}


{% block titulo %}Vehículos Tácticos{% endblock %}

{% block vertical %} {% include 'partes/vertical.html' %} {% endblock %}
{% block horizontal %} {% include 'partes/horizontal.html' %} {% endblock %}
{% block pie %} {% include 'partes/pie.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-1">Mecanizado Táctico</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 'asignacion_tactica' %}" class="btn btn-info fw-bold rounded-3">Asignaciones</a>
        <a href="{% url 'crear_inventario_tactico' %}" class="btn btn-primary fw-bold rounded-3">Registrar</a>
    </div>
</div>
{% endblock %}

{% block contenido %}
<div class="card shadow-sm rounded-3 border-0">
    <div class="card-header bg-primary py-1 rounded-top">
        <h5 class="card-title mb-0 text-white fw-bold"><i class="fas fa-car-alt me-3"></i>Inventario Táctico de Vehículos</h5>
    </div>
    <div class="card-body p-1">
        <div class="table-responsive">

            
<div class="table-responsive">
    < <table id="vehiculosTacticosTable" class="table table-sm table-striped fs-6">
        <thead style="background-color: #f8f9fa;">
            <tr>
                <th class="text-center">N°</th>
                <th class="text-center">Tipo</th>
                <th class="text-center">Modelo</th>
                <th class="text-center">Marca</th>
                <th class="text-center">Serial Chasis</th>
                <th class="text-center">Serial Motor</th>
                <th class="text-center">Fecha Creación</th>
                <th class="text-center">Estado</th>
                <th class="text-center">Unidad Asignada</th>
                <th class="text-center">Acciones</th>
            </tr>
        </thead>
        <tbody>
            {% for tactico in inventarios %}
            <tr>
                <td class="text-center fw-bold">{{ forloop.counter }}</td>
                <td class="text-center">{{ tactico.tipo }}</td>
                <td class="text-center">{{ tactico.modelo }}</td>
                <td class="text-center">{{ tactico.marca }}</td>
                <td class="text-center font-monospace">{{ tactico.serial_chasis }}</td>
                <td class="text-center font-monospace">{{ tactico.serial_motor }}</td>
                <td class="text-center">
                    <span class="badge bg-info text-dark">{{ tactico.fecha_creacion|date:"d-m-Y" }}</span>
                </td>
                <td class="text-center">
                    {% if tactico.asignaciones_temporales.exists %}
                        <span class="badge bg-warning">Asignado (Temporal)</span>
                    {% elif tactico.asignaciones_historial.exists %}
                        <span class="badge bg-danger">Asignado</span>
                    {% else %}
                        <span class="badge bg-success">Disponible</span>
                    {% endif %}
                </td>
                <td class="text-center">
                    {% if tactico.asignaciones_temporales.exists %}
                        {{ tactico.asignaciones_temporales.first.unidad.nombre }}
                    {% elif tactico.asignaciones_historial.exists %}
                        {{ tactico.asignaciones_historial.first.unidad.nombre }}
                    {% else %}
                        Sin asignar
                    {% endif %}
                </td>
                <td class="text-center">
                    <div class="d-flex justify-content-center gap-2">
                        <a href="{% url 'editar_inventario_tactico' tactico.pk %}" class="btn btn-primary btn-sm px-3" data-bs-toggle="tooltip" title="Editar">
                            <i class="fas fa-pen"></i>
                        </a>
                        <form action="{% url 'eliminar_inventario_tactico' tactico.pk %}" method="post" class="d-inline">
                            {% csrf_token %}
                            <button type="submit" class="btn btn-danger btn-sm px-3" data-bs-toggle="tooltip" title="Eliminar" {% if tactico.asignaciones_temporales.exists or tactico.asignaciones_historial.exists %}disabled{% endif %}>
                                <i class="fas fa-trash"></i>
                            </button>
                        </form>
                    </div>
                </td>
            </tr>
            {% empty %}
            <tr>
                <td colspan="16" class="text-center">No hay vehículos registrados.</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>

    
        </div>
    </div>
</div>
{% endblock %}

{% block js %}

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