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

{% block content %}
<div class="container-fluid">
    <nav aria-label="breadcrumb" class="mb-3">
        <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="{{ url_for('equipments_meters.lots') }}">Lots</a></li>
            <li class="breadcrumb-item active">{{ lot.name if lot else 'Nouveau lot' }}</li>
        </ol>
    </nav>
    
    <div class="row">
        <div class="col-lg-6">
            <div class="card">
                <div class="card-header">
                    <i class="bi bi-box-se me-1"></i>{{ title }}
                </div>
                <div class="card-body">
                    <form method="POST">
                        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                        <div class="mb-3">
                            <label for="name" class="form-label">Nom du lot *</label>
                            <input type="text" class="form-control" id="name" name="name" required
                                   value="{{ lot.name if lot else '' }}">
                        </div>
                        <div class="mb-3">
                            <label for="category_id" class="form-label">Catégorie</label>
                            <select id="category_id" name="category_id" class="form-select">
                                <option value="">-- Sans catégorie --</option>
                                {% for cat in categories %}
                                <option value="{{ cat.id }}" {% if lot and lot.category_id == cat.id %}selected{% endif %}>
                                    {{ cat.name }}
                                </option>
                                {% endfor %}
                            </select>
                        </div>
                        <div class="mt-3">
                            <button type="submit" class="btn btn-primary">
                                <i class="bi bi-check-lg me-1"></i>Enregistrer
                            </button>
                            <a href="{{ url_for('equipments_meters.lots') }}" class="btn btn-outline-secondary ms-2">
                                <i class="bi bi-x-lg me-1"></i>Annuler
                            </a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        
        {% if equipments %}
        <div class="col-lg-6">
            <div class="card">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <span><i class="bi bi-hdd-stack me-1"></i>Équipements ({{ equipments|length }})</span>
                </div>
                <div class="card-body p-0">
                    <div class="table-responsive">
                        <table class="table table-hover mb-0">
                            <thead>
                                <tr>
                                    <th>Nom</th>
                                    <th>Localisation</th>
                                    <th>Statut</th>
                                    <th></th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for eq in equipments %}
                                <tr>
                                    <td>
                                        <a href="{{ url_for('equipments.detail', id=eq.id) }}">
                                            {{ eq.name }}
                                        </a>
                                    </td>
                                    <td>
                                        {% if eq.room %}
                                            <a href="{{ url_for('rooms.detail', id=eq.room.id) }}">
                                                {{ eq.room.name }}
                                            </a>
                                        {% elif eq.location %}
                                            {{ eq.location }}
                                        {% else %}
                                            <span class="text-muted">—</span>
                                        {% endif %}
                                    </td>
                                    <td>
                                        {% if eq.status == 'active' %}
                                            <span class="badge bg-success">En service</span>
                                        {% elif eq.status == 'inactive' %}
                                            <span class="badge bg-secondary">Inactif</span>
                                        {% elif eq.status == 'maintenance' %}
                                            <span class="badge bg-warning text-dark">Maintenance</span>
                                        {% elif eq.status == 'retired' %}
                                            <span class="badge bg-danger">Retiré</span>
                                        {% else %}
                                            <span class="badge bg-secondary">{{ eq.status }}</span>
                                        {% endif %}
                                    </td>
                                    <td>
                                        <a href="{{ url_for('equipments.detail', id=eq.id) }}" 
                                           class="btn btn-sm btn-outline-primary">
                                            <i class="bi bi-eye"></i>
                                        </a>
                                    </td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            
            {% if equipments|length == 0 %}
            <div class="alert alert-info mt-3">
                <i class="bi bi-info-circle me-1"></i>
                Aucun équipement dans ce lot. Utilisez la page d'édition d'un équipement pour l'ajouter à ce lot.
            </div>
            {% endif %}
        </div>
        {% endif %}
    </div>
</div>
{% endblock %}
