{% extends "base.html" %}
{% block title %}Zones — GMAO Collège{% endblock %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
    <h1><i class="bi bi-geo-alt"></i> Zones</h1>
    <a href="{{ url_for('zones.create') }}" class="btn btn-primary"><i class="bi bi-plus-lg"></i> Nouvelle zone</a>
</div>

<div class="card">
    <div class="card-body">
        {% if zones %}
        <div class="table-responsive">
            <table class="table table-hover table-sm">
                <thead><tr><th>Nom</th><th>Bâtiment</th><th>Salles</th><th>Actions</th></tr></thead>
                <tbody>
                {% for zone in zones %}
                <tr>
                    <td>{{ zone.name }}</td>
                    <td>{{ zone.building.name }}</td>
                    <td><span class="badge bg-secondary">{{ zone.rooms|length }}</span></td>
                    <td>
                        <a href="{{ url_for('zones.edit', id=zone.id) }}" class="btn btn-sm btn-outline-primary" title="Modifier">
                            <i class="bi bi-pencil"></i>
                        </a>
                        <form action="{{ url_for('zones.delete', id=zone.id) }}" method="POST" style="display:inline;" onsubmit="return confirm('Supprimer cette zone ? Les salles associées ne seront pas supprimées.')">
                            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                            <button type="submit" class="btn btn-sm btn-outline-danger" title="Supprimer">
                                <i class="bi bi-trash"></i>
                            </button>
                        </form>
                    </td>
                </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
        {% else %}
        <p class="text-muted text-center">Aucune zone créée. <a href="{{ url_for('zones.create') }}">Créer une zone</a></p>
        {% endif %}
    </div>
</div>
{% endblock %}