{% extends "base.html" %}
{% block title %}Tâches Planifiées — GMAO Collège{% endblock %}

{% block content %}
<div class="d-flex justify-content-end mb-3"><form method="post" action="{{ url_for('planning.reconcile_scheduled') }}"><button class="btn btn-outline-primary" type="submit"><i class="bi bi-calendar-check"></i> Réconcilier avec les disponibilités</button></form></div>
<div class="d-flex justify-content-between align-items-center mb-4">
    <h1><i class="bi bi-calendar-week"></i> Tâches Planifiées</h1>
    <div>
        <select class="form-select d-inline-block w-auto" id="statusFilter">
            <option value="all">Tous les statuts</option>
            <option value="planned" {% if status == 'planned' %}selected{% endif %}>Planifiées</option>
            <option value="in_progress" {% if status == 'in_progress' %}selected{% endif %}>En cours</option>
            <option value="completed" {% if status == 'completed' %}selected{% endif %}>Terminées</option>
            <option value="postponed" {% if status == 'postponed' %}selected{% endif %}>Reportées</option>
        </select>
    </div>
</div>

{% if tasks %}
<table class="table table-hover">
    <thead class="table-light">
        <tr>
            <th>Date</th>
            <th>Heure</th>
            <th>Tâche</th>
            <th>Équipement</th>
            <th>Salle</th>
            <th>Durée</th>
            <th>Statut</th>
            <th>Actions</th>
        </tr>
    </thead>
    <tbody>
        {% for task in tasks %}
        <tr>
            <td>{{ task.scheduled_date.strftime('%d/%m/%Y') if task.scheduled_date else '-' }}</td>
            <td>{{ task.scheduled_start.strftime('%H:%M') if task.scheduled_start else '- - -' }}</td>
            <td><strong>{{ task.lot_task.tache if task.lot_task else '-' }}</strong></td>
            <td>{{ task.equipment.name if task.equipment else '-' }}{% if task.company %}<div class="small text-primary"><i class="bi bi-building"></i> {{ task.company.name }}{% if task.contract %} · {{ task.contract.name }}{% endif %}</div>{% endif %}</td>
            <td>{{ task.room.name if task.room else '-' }}</td>
            <td>{% if task.estimated_duration %}{{ task.estimated_duration }}{% elif task.lot_task and task.lot_task.duree_minutes %}{{ task.lot_task.duree_minutes }}{% else %}-{% endif %} min</td>
            <td>
                {% if task.status == 'planned' %}
                    {% if task.is_overdue %}
                    <span class="badge bg-danger">En retard</span>
                    {% else %}
                    <span class="badge bg-info">Planifiée</span>
                    {% endif %}
                {% elif task.status == 'in_progress' %}
                <span class="badge bg-warning">En cours</span>
                {% elif task.status == 'completed' %}
                <span class="badge bg-success">Terminée</span>
                {% elif task.status == 'postponed' %}
                <span class="badge bg-secondary">Reportée</span>
                {% endif %}
            </td>
            <td>
                <a href="{{ url_for('planning.scheduled_detail', id=task.id) }}" class="btn btn-sm btn-outline-primary">
                    <i class="bi bi-eye"></i>
                </a>
            </td>
        </tr>
        {% endfor %}
    </tbody>
</table>
{% else %}
<div class="alert alert-info">
    <i class="bi bi-info-circle"></i> Aucune tâche planifiée pour le moment.
</div>
{% endif %}
{% endblock %}
