{% 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-building-gear"></i> Gestion des Services</h1>
        <a href="{{ url_for('services.create') }}" class="btn btn-primary">
            <i class="bi bi-plus"></i> Nouveau service
        </a>
    </div>

    <!-- Liste des services -->
    <div class="card">
        <div class="card-header">
            <h5 class="mb-0">Services du département ({{ services.total }})</h5>
        </div>
        <div class="table-responsive">
            <table class="table table-hover mb-0">
                <thead>
                    <tr>
                        <th>Service</th>
                        <th>Responsable</th>
                        <th>Chargé d'opération</th>
                        <th>Lots gérés</th>
                        <th>Statut</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    {% for service in services %}
                    <tr>
                        <td><strong>{{ service.name }}</strong></td>
                        <td>{{ service.manager.full_name if service.manager else '-' }}</td>
                        <td>{{ service.operator.full_name if service.operator else '-' }}</td>
                        <td>
                            {% set lot_count = lot_counts.get(service.id, 0) %}
                            <span class="badge bg-info">{{ lot_count }} lot(s)</span>
                        </td>
                        <td>
                            {% if service.is_active %}
                                <span class="badge bg-success">Actif</span>
                            {% else %}
                                <span class="badge bg-secondary">Inactif</span>
                            {% endif %}
                        </td>
                        <td>
                            <a href="{{ url_for('services.detail', id=service.id) }}" class="btn btn-sm btn-outline-primary">
                                <i class="bi bi-eye"></i> Voir
                            </a>
                            <a href="{{ url_for('services.edit', id=service.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 %}