{% extends 'base.html' %}
{% load static %}

{% block content %}
<div class="container-fluid py-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h3 class="fw-bold mb-0">Техническое обслуживание</h3>
        <a href="{% url 'maintenance_add' %}" class="btn btn-primary rounded-pill px-4">
            <i class="bi bi-plus-lg me-2"></i>Запланировать ТО
        </a>
    </div>

    <div class="card border-0 shadow-sm">
        <div class="table-responsive">
            <table class="table table-hover align-middle mb-0">
                <thead class="bg-light">
                    <tr>
                        <th class="border-0 px-4">Техника</th>
                        <th class="border-0">Тип</th>
                        <th class="border-0">Плановая дата</th>
                        <th class="border-0">Статус</th>
                        <th class="border-0">Исполнитель</th>
                        <th class="border-0 text-end px-4">Действия</th>
                    </tr>
                </thead>
                <tbody>
                    {% for m in maintenances %}
                    <tr>
                        <td class="px-4">
                            <div class="fw-bold"><a href="{{ m.fleet_unit.get_absolute_url }}">{{ m.fleet_unit.name }}</a></div>
                            <div class="small text-muted">{{ m.fleet_unit.plate_number|default:m.fleet_unit.vin }}</div>
                        </td>
                        <td><span class="badge bg-light text-dark border">{{ m.get_m_type_display }}</span></td>
                        <td>{{ m.planned_date }}</td>
                        <td>
                            <span class="badge bg-{{ m.status|yesno:'success,warning,secondary' }} rounded-pill">
                                {% if m.status == 'planned' %}Планируется
                                {% elif m.status == 'in_progress' %}В процессе
                                {% else %}Выполнено{% endif %}
                            </span>
                        </td>
                        <td>{{ m.mechanic|default:"-" }}</td>
                        <td class="text-end px-4">
                            <a href="{% url 'maintenance_detail' m.pk %}" class="btn btn-sm btn-outline-primary rounded-pill px-3">Открыть</a>
                        </td>
                    </tr>
                    {% empty %}
                    <tr>
                        <td colspan="6" class="text-center py-5 text-muted">Нет запланированных ТО</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}
