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

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
    <h1><i class="bi bi-clipboard"></i> Tâches Administratives</h1>
    <a href="{{ url_for('planning.new_admin_task') }}" class="btn btn-primary">
        <i class="bi bi-plus"></i> Nouvelle tâche
    </a>
</div>

<div class="row">
    <div class="col-md-6">
        <h5>Récurrentes</h5>
        <table class="table table-hover">
            <thead class="table-light">
                <tr>
                    <th>Nom</th>
                    <th>Pour</th>
                    <th>Fréquence</th>
                    <th>Heure</th>
                    <th>Durée</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
                {% for task in tasks if task.frequency in ['daily', 'weekly'] %}
                <tr>
                    <td><strong>{{ task.name }}</strong></td>
                    <td>{{ task.user.display_name if task.user and task.user.display_name else (task.user.username if task.user else 'Tous les techniciens') }}</td>
                    <td>
                        {% if task.frequency == 'daily' %}
                        <span class="badge bg-primary">Quotidien</span>
                        {% elif task.frequency == 'weekly' %}
                        <span class="badge bg-info">Hebdomadaire</span>
                        {% endif %}
                    </td>
                    <td>{{ task.start_time.strftime('%H:%M') if task.start_time else '-' }}</td>
                    <td>{{ task.duration_minutes }} min</td>
                    <td>
                        <a href="{{ url_for('planning.edit_admin_task', id=task.id) }}" class="btn btn-sm btn-outline-primary">
                            <i class="bi bi-pencil"></i>
                        </a>
                    </td>
                </tr>
                {% else %}
                <tr>
                    <td colspan="6" class="text-muted text-center">Aucune tâche quotidienne/hebdomadaire</td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
    
    <div class="col-md-6">
        <h5>Mensuelles / Annuelle</h5>
        <table class="table table-hover">
            <thead class="table-light">
                <tr>
                    <th>Nom</th>
                    <th>Pour</th>
                    <th>Fréquence</th>
                    <th>Heure</th>
                    <th>Durée</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
                {% for task in tasks if task.frequency in ['monthly', 'yearly'] %}
                <tr>
                    <td><strong>{{ task.name }}</strong></td>
                    <td>{{ task.user.display_name if task.user and task.user.display_name else (task.user.username if task.user else 'Tous les techniciens') }}</td>
                    <td>
                        {% if task.frequency == 'monthly' %}
                        <span class="badge bg-warning">Mensuel</span>
                        {% else %}
                        <span class="badge bg-secondary">Annuel</span>
                        {% endif %}
                    </td>
                    <td>{{ task.start_time.strftime('%H:%M') if task.start_time else '-' }}</td>
                    <td>{{ task.duration_minutes }} min</td>
                    <td>
                        <a href="{{ url_for('planning.edit_admin_task', id=task.id) }}" class="btn btn-sm btn-outline-primary">
                            <i class="bi bi-pencil"></i>
                        </a>
                    </td>
                </tr>
                {% else %}
                <tr>
                    <td colspan="6" class="text-muted text-center">Aucune tâche mensuelle/annuelle</td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
</div>
{% endblock %}
