{% 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 'part_request_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">Дата создания</th>
                        <th class="border-0 text-end px-4">Действия</th>
                    </tr>
                </thead>
                <tbody>
                    {% for r in requests %}
                    <tr>
                        <td class="px-4">
                            <div class="fw-bold">{{ r.fleet_unit.name }}</div>
                            <div class="small text-muted">{{ r.fleet_unit.plate_number|default:r.fleet_unit.vin }}</div>
                        </td>
                        <td>{{ r.part_name }}</td>
                        <td>{{ r.article_number|default:"-" }}</td>
                        <td>{{ r.quantity }}</td>
                        <td>
                            {% if r.status == 'draft' %}<span class="badge bg-secondary">Черновик</span>
                            {% elif r.status == 'sent' %}<span class="badge bg-info text-white">Отправлено</span>
                            {% elif r.status == 'ordered' %}<span class="badge bg-primary">Заказано</span>
                            {% elif r.status == 'delivered' %}<span class="badge bg-success">Доставлено</span>
                            {% endif %}
                        </td>
                        <td class="small">{{ r.created_at|date:"d.m.Y H:i" }}</td>
                        <td class="text-end px-4">
                            <div class="btn-group">
                                <button type="button" class="btn btn-sm btn-outline-secondary dropdown-toggle rounded-pill px-3" data-bs-toggle="dropdown">
                                    Действие
                                </button>
                                <ul class="dropdown-menu dropdown-menu-end shadow-sm border-0">
                                    <li><a class="dropdown-item" href="#">Изменить статус</a></li>
                                    <li><a class="dropdown-item" href="#">Экспорт Excel</a></li>
                                    <li><hr class="dropdown-divider"></li>
                                    <li><a class="dropdown-item text-danger" href="#">Удалить</a></li>
                                </ul>
                            </div>
                        </td>
                    </tr>
                    {% empty %}
                    <tr>
                        <td colspan="7" class="text-center py-5 text-muted">Нет активных заявок</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}
