{% extends "base.html" %}
{% block title %}Déplacer {{ equipment.name }} — GMAO{% endblock %}
{% block content %}
<div class="container-fluid" style="max-width: 850px">
  <h1 class="h3 mb-4"><i class="bi bi-arrow-left-right"></i> Déplacer {{ equipment.name }}</h1>
  <div class="card"><div class="card-body">
    <dl class="row">
      <dt class="col-sm-4">Salle actuelle</dt><dd class="col-sm-8">{{ current_room.full_name if current_room else 'Stock non localisé' }}</dd>
      <dt class="col-sm-4">Mobilité</dt><dd class="col-sm-8">{{ equipment.mobility|replace('_', ' ')|title }}</dd>
      {% if equipment.is_group %}<dt class="col-sm-4">Quantité disponible</dt><dd class="col-sm-8"><strong>{{ max_quantity }}</strong> non individualisée(s)</dd>{% endif %}
    </dl>
    <form method="post">
      <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
      {% if equipment.is_group %}
      <div class="mb-3">
        <label for="quantity" class="form-label">Quantité à déplacer</label>
        <input id="quantity" name="quantity" type="number" class="form-control" min="1" max="{{ max_quantity }}" value="1" required>
        <div class="form-text">Les unités déjà individualisées doivent être déplacées depuis leur propre fiche.</div>
      </div>
      {% endif %}
      <div class="mb-3">
        <label for="room_id" class="form-label">Salle cible</label>
        <select id="room_id" name="room_id" class="form-select" required>
          <option value="">— Sélectionner —</option>
          {% for room in rooms %}<option value="{{ room.id }}">{{ room.full_name }}</option>{% endfor %}
        </select>
      </div>
      <div class="mb-3"><label for="reason" class="form-label">Motif</label><input id="reason" name="reason" class="form-control" maxlength="255"></div>
      <button class="btn btn-primary" type="submit" {% if equipment.is_group and max_quantity < 1 %}disabled{% endif %}><i class="bi bi-check-lg"></i> Confirmer le déplacement</button>
      <a href="{{ url_for('equipments.detail', id=equipment.id) }}" class="btn btn-outline-secondary">Annuler</a>
    </form>
  </div></div>
</div>
{% endblock %}
