{% extends "base.html" %}
{% block content %}
<div class="container-fluid py-3" style="max-width:1100px">
  <h1 class="h3">Prévisualiser « {{ profile.name }} »</h1>
  <p class="text-muted">Aucun équipement n’est créé avant validation. Une réapplication ajoute uniquement les quantités manquantes.</p>
  <form method="post"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
    <div class="card mb-3"><div class="card-header">Locaux concernés</div><div class="card-body row g-2">
      {% for room in rooms %}<div class="col-md-4"><label class="form-check"><input class="form-check-input" type="checkbox" name="room_ids" value="{{ room.id }}" checked><span class="form-check-label">{{ room.full_name }}</span></label></div>{% else %}<div class="col-12"><div class="alert alert-warning">Aucun local sélectionné. Ouvrez cette page depuis la fiche d’un local.</div></div>{% endfor %}
    </div></div>
    <div class="card mb-3"><div class="card-header">Propositions à accepter ou modifier</div><div class="table-responsive"><table class="table align-middle mb-0"><thead><tr><th>Accepter</th><th>Équipement</th><th>Cible</th>{% for room in rooms %}<th>{{ room.name }}<br><small>existant → cible</small></th>{% endfor %}</tr></thead><tbody>
      {% for item in items %}<tr><td><input class="form-check-input" type="checkbox" name="item_ids" value="{{ item.id }}" checked></td><td>{{ item.label }}</td><td><input class="form-control" type="number" min="1" name="quantity_{{ item.id }}" value="{{ item.quantity }}"></td>{% for room in rooms %}{% set have = existing.get((room.id, item.id), 0) %}<td>{{ have }} → {{ item.quantity }}{% if have >= item.quantity %}<span class="badge text-bg-success ms-1">déjà présent</span>{% else %}<span class="badge text-bg-warning ms-1">+{{ item.quantity - have }}</span>{% endif %}</td>{% endfor %}</tr>{% else %}<tr><td colspan="4">Ce profil ne contient aucune proposition.</td></tr>{% endfor %}
    </tbody></table></div></div>
    <button class="btn btn-primary" name="validate" value="1">Appliquer les éléments cochés</button><a class="btn btn-link" href="{{ url_for('room_profiles.edit', id=profile.id) }}">Annuler</a>
  </form>
</div>
{% endblock %}
