{% extends "base.html" %}
{% block title %}Lier consommable — GMAO{% endblock %}

{% block content %}
<div class="container py-4">
    <div class="row justify-content-center">
        <div class="col-md-6">
            <div class="card shadow-sm">
                <div class="card-header bg-dark text-white">
                    <h5 class="mb-0"><i class="bi bi-box-seam"></i> Associer consommable à {{ equipment.name }}</h5>
                </div>
                <div class="card-body">
                    <form method="POST">
                        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                        <div class="mb-3">
                            <label class="form-label">Consommable</label>
                            <select name="part_id" class="form-select" required>
                                <option value="">-- Choisir un consommable --</option>
                                {% for p in parts %}
                                <option value="{{ p.id }}">{{ p.name }} ({{ p.reference }})</option>
                                {% endfor %}
                            </select>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">Seuil d'alerte stock bas (unité)</label>
                            <input type="number" name="threshold" class="form-control" value="1" min="1">
                            <div class="form-text">L'appareil signalera un besoin de remplacement quand le stock global tombe sous ce seuil.</div>
                        </div>
                        <div class="d-flex gap-2">
                            <button type="submit" class="btn btn-dark">Lier le consommable</button>
                            <a href="{{ url_for('equipments.detail', id=equipment.id) }}" class="btn btn-outline-secondary">Annuler</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
