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

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
    <h1><i class="bi bi-box"></i> Consommables</h1>
    <a href="{{ url_for('planning.new_consumable') }}" class="btn btn-primary">
        <i class="bi bi-plus"></i> Nouveau consommable
    </a>
</div>

<table class="table table-hover">
    <thead class="table-light">
        <tr>
            <th>Catégorie</th>
            <th>Nom</th>
            <th>Référence</th>
            <th>Stock</th>
            <th>Stock min</th>
            <th>Unité</th>
            <th>Prix unitaire</th>
            <th>Fournisseur</th>
            <th>Statut</th>
            <th>Actions</th>
        </tr>
    </thead>
    <tbody>
        {% for cons in consumables %}
        <tr>
            <td><span class="badge bg-secondary">{{ cons.category or '-' }}</span></td>
            <td><strong>{{ cons.name }}</strong></td>
            <td><code>{{ cons.reference or '-' }}</code></td>
            <td>{{ cons.quantity }}</td>
            <td>{{ cons.min_quantity }}</td>
            <td>{{ cons.unit }}</td>
            <td>{% if cons.unit_price %}{{ "%.2f"|format(cons.unit_price) }} €{% else %}-{% endif %}</td>
            <td>{{ cons.supplier.name if cons.supplier else '-' }}</td>
            <td>
                {% if cons.is_low_stock %}
                <span class="badge bg-danger">Stock bas</span>
                {% else %}
                <span class="badge bg-success">OK</span>
                {% endif %}
            </td>
            <td>
                <a href="{{ url_for('planning.edit_consumable', id=cons.id) }}" class="btn btn-sm btn-outline-primary">
                    <i class="bi bi-pencil"></i>
                </a>
            </td>
        </tr>
        {% else %}
        <tr>
            <td colspan="10" class="text-center text-muted py-4">
                Aucun consommable. <a href="{{ url_for('planning.new_consumable') }}">Créer le premier</a>
            </td>
        </tr>
        {% endfor %}
    </tbody>
</table>
{% endblock %}