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

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
    <h1><i class="bi bi-door-open"></i> Salles</h1>
    <a href="{{ url_for('equipments.create_room') }}" class="btn btn-primary"><i class="bi bi-plus-lg"></i> Nouvelle salle</a>
</div>

<div class="card">
    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-hover table-sm">
                <thead><tr><th>Code</th><th>Nom</th><th>Bâtiment</th><th>Étage</th><th>Type</th><th>Équipements</th><th>Actions</th></tr></thead>
                <tbody>
                {% for room in rooms %}
                <tr>
                    <td><code>{{ room.code or '—' }}</code></td>
                    <td>{{ room.name }}</td>
                    <td>{{ room.building.name }}</td>
                    <td>{{ room.floor }}</td>
                    <td>
                        {% if room.room_type %}
                        <span class="badge" style="background-color: {{ room.room_type.color|hex_color }}; color: {{ room.room_type.color|text_color }};">{{ room.room_type.name }}</span>
                        {% else %}
                        <span class="text-muted">—</span>
                        {% endif %}
                    </td>
                    <td><span class="badge bg-secondary">{{ room.equipments.count() }}</span></td>
                    <td>
                        <a href="{{ url_for('equipments.room_detail', id=room.id) }}" class="btn btn-sm btn-outline-info" title="Voir">
                            <i class="bi bi-eye"></i>
                        </a>
                        <a href="{{ url_for('equipments.edit_room', id=room.id) }}" class="btn btn-sm btn-outline-primary" title="Modifier">
                            <i class="bi bi-pencil"></i>
                        </a>
                        <form action="{{ url_for('equipments.delete_room', id=room.id) }}" method="POST" style="display:inline;" onsubmit="return confirm('Supprimer cette salle ?')">
                            <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>
    </div>
</div>
{% endblock %}