{% extends "base.html" %}
{% block title %}Contraintes de zone - GMAO{% endblock %}
{% block content %}
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-3">
        <h2 class="h4"><i class="bi bi-shield-exclamation"></i> Contraintes d'indisponibilite des salles</h2>
        <a href="{{ url_for('constraints.create') }}" class="btn btn-primary btn-sm">
            <i class="bi bi-plus-circle"></i> Nouvelle contrainte
        </a>
    </div>
    {% if constraints %}
    <div class="card border-0 shadow-sm">
        <div class="table-responsive">
            <table class="table table-hover mb-0">
                <thead><tr><th>Salle</th><th>Type</th><th>Jour</th><th>Heures</th><th>Raison</th><th>Source</th><th>Actif</th><th></th></tr></thead>
                <tbody>
                {% for c in constraints %}
                <tr>
                    <td>{% if c.room %}<span class="badge bg-info">{{ c.room.name }}</span>{% else %}<span class="badge bg-secondary">Toutes</span>{% endif %}</td>
                    <td><span class="badge bg-{% if c.constraint_type == 'time' %}warning text-dark{% elif c.constraint_type == 'occupancy' %}danger{% else %}info{% endif %}">{{ c.constraint_type }}</span></td>
                    <td>{{ c.day_name }}</td>
                    <td>{% if c.start_time %}{{ c.start_time.strftime('%H:%M') }} - {{ c.end_time.strftime('%H:%M') if c.end_time else '?' }}{% else %}Toute journee{% endif %}</td>
                    <td>{{ c.reason or '—' }}</td>
                    <td><small class="text-muted">{{ c.source }}</small></td>
                    <td>{% if c.is_active %}<span class="badge bg-success">Oui</span>{% else %}<span class="badge bg-secondary">Non</span>{% endif %}</td>
                    <td><a href="{{ url_for('constraints.edit', id=c.id) }}" class="btn btn-sm btn-outline-primary"><i class="bi bi-pencil"></i></a></td>
                </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
    {% else %}
    <div class="text-center py-5 text-muted">
        <i class="bi bi-shield-check" style="font-size:3rem;"></i>
        <p class="mt-2">Aucune contrainte definie</p>
        <a href="{{ url_for('constraints.create') }}" class="btn btn-primary"><i class="bi bi-plus-circle"></i> Creer une contrainte</a>
    </div>
    {% endif %}
</div>
{% endblock %}