{% extends "base.html" %}
{% block content %}

<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1><i class="bi bi-boxes"></i> Gestion des Lots</h1>
        <a href="{{ url_for('equipments.index') }}" class="btn btn-secondary">
            <i class="bi bi-arrow-left"></i> Retour aux équipements
        </a>
    </div>

    <!-- Filtres -->
    <div class="card mb-4">
        <div class="card-body">
            <form method="get" class="row g-3">
                <div class="col-md-6">
                    <input type="text" name="search" class="form-control" placeholder="Rechercher un lot..." value="{{ request.args.get('search', '') }}">
                </div>
                <div class="col-md-4">
                    <select name="company_id" class="form-select">
                        <option value="">Toutes les entreprises</option>
                        {% for company in companies %}
                        <option value="{{ company.id }}" {% if request.args.get('company_id')|int == company.id %}selected{% endif %}>
                            {{ company.name }}
                        </option>
                        {% endfor %}
                    </select>
                </div>
                <div class="col-md-2">
                    <button type="submit" class="btn btn-primary w-100">Filtrer</button>
                </div>
            </form>
        </div>
    </div>

    <!-- Liste des lots -->
    <div class="card">
        <div class="card-header">
            <h5 class="mb-0">Liste des Lots ({{ lots.total }})</h5>
        </div>
        <div class="table-responsive">
            <table class="table table-hover mb-0">
                <thead>
                    <tr>
                        <th>Lot</th>
                        <th>Catégories</th>
                        <th>Entreprise</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    {% for lot in lots %}
                    <tr>
                        <td><strong>{{ lot.name }}</strong></td>
                        <td><span class="badge bg-info">{{ lot.categories.count() }} catégorie(s)</span></td>
                        <td>
                            {% if lot.company %}
                                <span class="badge bg-success">{{ lot.company.name }}</span>
                            {% else %}
                                <span class="text-muted">Non assigné</span>
                            {% endif %}
                        </td>
                        <td>
                            <a href="{{ url_for('lots.detail', id=lot.id) }}" class="btn btn-sm btn-outline-primary">
                                <i class="bi bi-eye"></i> Voir
                            </a>
                            <a href="{{ url_for('lots.edit', id=lot.id) }}" class="btn btn-sm btn-outline-warning">
                                <i class="bi bi-pencil"></i> Modifier
                            </a>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>

{% endblock %}