{% extends 'base.html' %}

{% block content %}
<div class="container-fluid py-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1 class="h2">Снабжение</h1>
    </div>

    <div class="row">
        <!-- Part Requests Section -->
        <div class="col-lg-8">
            <div class="card shadow-sm mb-4">
                <div class="card-header bg-white py-3">
                    <h5 class="card-title mb-0">Заявки на запчасти</h5>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-hover align-middle">
                            <thead class="table-light">
                                <tr>
                                    <th>Дата</th>
                                    <th>Техника</th>
                                    <th>Деталь</th>
                                    <th>Кол-во</th>
                                    <th>Статус</th>
                                    <th>Действия</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for req in requests %}
                                <tr>
                                    <td>{{ req.created_at|date:"d.m.Y" }}</td>
                                    <td>
                                        <a href="{% url 'fleet_detail' req.fleet_unit.pk %}" class="text-decoration-none">
                                            {{ req.fleet_unit.name }}
                                        </a>
                                    </td>
                                    <td>{{ req.part_name }}</td>
                                    <td>{{ req.quantity }}</td>
                                    <td>
                                        <span class="badge rounded-pill bg-{{ req.status|yesno:'info,secondary' }}">
                                            {{ req.get_status_display }}
                                        </span>
                                    </td>
                                    <td>
                                        <a href="#" class="btn btn-sm btn-outline-primary">Управление</a>
                                    </td>
                                </tr>
                                {% empty %}
                                <tr>
                                    <td colspan="6" class="text-center py-4">Нет активных заявок</td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>

        <!-- Suppliers Section -->
        <div class="col-lg-4">
            <div class="card shadow-sm">
                <div class="card-header bg-white py-3 d-flex justify-content-between align-items-center">
                    <h5 class="card-title mb-0">Поставщики</h5>
                    <a href="{% url 'supplier_add' %}" class="btn btn-sm btn-primary">
                        <i class="bi bi-plus-lg"></i> Добавить
                    </a>
                </div>
                <div class="card-body">
                    <div class="list-group list-group-flush">
                        {% for supplier in suppliers %}
                        <div class="list-group-item px-0 py-3">
                            <div class="d-flex w-100 justify-content-between align-items-center">
                                <h6 class="mb-1">{{ supplier.name }}</h6>
                                <a href="{% url 'supplier_edit' supplier.pk %}" class="btn btn-sm btn-link p-0 text-muted">
                                    <i class="bi bi-pencil-square"></i>
                                </a>
                            </div>
                            <p class="mb-1 small text-muted">
                                <strong>Менеджер:</strong> {{ supplier.representative_name|default:"-" }}<br>
                                <strong>Тел:</strong> {{ supplier.phone|default:"-" }}<br>
                                <strong>Email:</strong> {{ supplier.email|default:"-" }}<br>
                                <strong>Договор:</strong> {{ supplier.contract_number|default:"-" }}
                            </p>
                        </div>
                        {% empty %}
                        <div class="text-center py-3 text-muted">Список поставщиков пуст</div>
                        {% endfor %}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
