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

{% block content %}
<h1 class="mb-4">{{ title }}</h1>
<div class="card mb-4"><div class="card-body">
<form method="POST">
    {{ form.hidden_tag() }}
    <div class="row">
        <div class="col-md-4 mb-3">{{ form.name.label(class="form-label") }}{{ form.name(class="form-control") }}</div>
        <div class="col-md-3 mb-3">{{ form.code.label(class="form-label") }}{{ form.code(class="form-control") }}</div>
        <div class="col-md-3 mb-3">{{ form.floor.label(class="form-label") }}{{ form.floor(class="form-control") }}</div>
        <div class="col-md-2 mb-3">{{ form.building_id.label(class="form-label") }}{{ form.building_id(class="form-select") }}</div>
        <div class="col-md-4 mb-3">{{ form.room_type_id.label(class="form-label") }}{{ form.room_type_id(class="form-select") }}</div>
    </div>
    <div class="mt-3">
        <button type="submit" class="btn btn-primary"><i class="bi bi-check-lg"></i> Enregistrer</button>
        <a href="{{ url_for('equipments.rooms') }}" class="btn btn-outline-secondary">Annuler</a>
    </div>
</form>
</div></div>

{% if room and equipments %}
<div class="card">
    <div class="card-header">
        <h5 class="mb-0"><i class="bi bi-hdd"></i> Équipements dans cette salle ({{ equipments|length }})</h5>
    </div>
    <div class="card-body">
        {% if equipments %}
        <div class="table-responsive">
            <table class="table table-sm table-hover">
                <thead>
                    <tr>
                        <th>Nom</th>
                        <th>Catégorie</th>
                        <th>État</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                {% for eq in equipments %}
                <tr>
                    <td>{{ eq.name }}</td>
                    <td>{{ eq.category.name if eq.category else '—' }}</td>
                    <td>
                        {% if eq.state == 'operationnel' %}
                        <span class="badge bg-success">Opérationnel</span>
                        {% elif eq.state == 'en_panne' %}
                        <span class="badge bg-danger">En panne</span>
                        {% elif eq.state == 'en_maintenance' %}
                        <span class="badge bg-warning">En maintenance</span>
                        {% else %}
                        <span class="badge bg-secondary">{{ eq.state }}</span>
                        {% endif %}
                    </td>
                    <td>
                        <a href="{{ url_for('equipments.edit', id=eq.id) }}" class="btn btn-sm btn-outline-primary" title="Modifier l'équipement">
                            <i class="bi bi-pencil"></i>
                        </a>
                        <a href="{{ url_for('interventions.create', equipment_id=eq.id) }}" class="btn btn-sm btn-outline-success" title="Créer une intervention">
                            <i class="bi bi-tools"></i>
                        </a>
                    </td>
                </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
        {% else %}
        <p class="text-muted">Aucun équipement dans cette salle.</p>
        {% endif %}
    </div>
</div>
{% endif %}
{% endblock %}