{% extends "base.html" %}
{% block content %}

<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1><i class="bi bi-box"></i> Lot: {{ lot.name }}</h1>
        <div>
            <a href="{{ url_for('lots.edit', id=lot.id) }}" class="btn btn-warning me-2">
                <i class="bi bi-pencil"></i> Modifier
            </a>
            <a href="{{ url_for('lots.index') }}" class="btn btn-secondary">
                <i class="bi bi-arrow-left"></i> Retour
            </a>
        </div>
    </div>

    <!-- Info du lot -->
    <div class="row">
        <div class="col-md-6">
            <div class="card mb-4">
                <div class="card-header">
                    <h5>Informations du Lot</h5>
                </div>
                <div class="card-body">
                    <p><strong>Nom:</strong> {{ lot.name }}</p>
                    <p><strong>Entreprise assignée:</strong>
                        {% if lot.company %}
                            <span class="badge bg-success">{{ lot.company.name }}</span>
                        {% else %}
                            <span class="text-muted">Aucune entreprise assignée</span>
                        {% endif %}
                    </p>
                </div>
            </div>
        </div>
        <div class="col-md-6">
            <div class="card mb-4">
                <div class="card-header">
                    <h5>Statistiques</h5>
                </div>
                <div class="card-body">
                    <p><strong>Catégorie:</strong> 
                        {% if lot.category %}
                            <a href="{{ url_for('equipments.category_detail', id=lot.category.id) }}">{{ lot.category.name }}</a>
                        {% else %}
                            <span class="text-muted">Non assignée</span>
                        {% endif %}
                    </p>
                </div>
            </div>
        </div>
    </div>

    <!-- Tâches préventives du lot -->
    <div class="card">
        <div class="card-header">
            <h5 class="mb-0">Tâches préventives associées</h5>
        </div>
        <div class="table-responsive">
            <table class="table table-hover mb-0">
                <thead>
                    <tr>
                        <th>N°</th>
                        <th>Tâche</th>
                        <th>Périodicité</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    {% for task in lot.tasks %}
                    <tr>
                        <td>{{ task.num_tache }}</td>
                        <td>{{ task.tache }}</td>
                        <td>{{ task.periodicite }}</td>
                        <td>
                            <a href="{{ url_for('lots.task_detail', lot_id=lot.id, task_id=task.id) }}" class="btn btn-sm btn-outline-primary">
                                <i class="bi bi-eye"></i>
                            </a>
                        </td>
                    </tr>
                    {% else %}
                    <tr>
                        <td colspan="4" class="text-center text-muted">Aucune tâche préventive associée.</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>

{% endblock %}