{% extends "base.html" %}
{% block title %}{{ training.name }} — GMAO{% endblock %}

{% block content %}

<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1><i class="bi bi-mortarboard"></i> {{ training.name }}</h1>
        <div>
            {% if current_user.is_admin() %}
            <a href="{{ url_for('trainings.edit', id=training.id) }}" class="btn btn-outline-secondary"><i class="bi bi-pencil"></i> Modifier</a>
            {% endif %}
            <a href="{{ url_for('trainings.index') }}" class="btn btn-secondary">Retour</a>
        </div>
    </div>
    
    <div class="row">
        <div class="col-md-6">
            <div class="card mb-3">
                <div class="card-header"><i class="bi bi-info-circle"></i> Informations</div>
                <div class="card-body">
                    <p><strong>Date :</strong> {{ training.start_date.strftime('%d/%m/%Y') }} au {{ training.end_date.strftime('%d/%m/%Y') }}</p>
                    {% if training.location %}<p><strong>Lieu :</strong> {{ training.location }}</p>{% endif %}
                    {% if training.max_participants %}<p><strong>Max participants :</strong> {{ training.max_participants }}</p>{% endif %}
                    {% if training.description %}<p><strong>Description :</strong> {{ training.description }}</p>{% endif %}
                </div>
            </div>
        </div>
        
        <div class="col-md-6">
            <div class="card">
                <div class="card-header"><i class="bi bi-people"></i> Participants ({{ participants|length }})</div>
                <div class="card-body">
                    {% if participants %}
                    <ul class="list-unstyled">
                    {% for p in participants %}
                    <li class="mb-2">{{ p.user.full_name }} <span class="badge bg-secondary">{{ p.status }}</span></li>
                    {% endfor %}
                    </ul>
                    {% else %}
                    <p class="text-muted">Aucun participant inscrit.</p>
                    {% endif %}
                    
                    {% set is_registered = participant_users.get(current_user.id) %}
                    <form method="POST" action="{% if is_registered %}{{ url_for('trainings.unregister', id=training.id) }}{% else %}{{ url_for('trainings.register', id=training.id) }}{% endif %}" class="mt-3">
                        <button type="submit" class="btn btn-{% if is_registered %}warning{% else %}success{% endif %}">
                            {% if is_registered %}<i class="bi bi-x-lg"></i> Se désinscrire{% else %}<i class="bi bi-plus-lg"></i> S'inscrire{% endif %}
                        </button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

{% endblock %}
