{% extends "base.html" %}
{% block title %}Nouvelle formation — 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> Nouvelle formation</h1>
        <a href="{{ url_for('trainings.index') }}" class="btn btn-secondary"><i class="bi bi-arrow-left"></i> Retour</a>
    </div>
    <div class="card"><div class="card-body">
        <form method="POST">
            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
            {% if source_interpretation is defined %}
            <div class="alert alert-info"><i class="bi bi-envelope"></i> Prérempli depuis un mail. Vérifiez les dates avant de confirmer.</div>
            {% endif %}
            <div class="mb-3"><label class="form-label">Titre *</label><input type="text" name="title" class="form-control" value="{{ training.name if training is defined else '' }}" required></div>
            <div class="mb-3"><label class="form-label">Description</label><textarea name="description" class="form-control" rows="3">{{ training.description if training is defined and training.description else '' }}</textarea></div>
            <div class="row mb-3">
                <div class="col-md-6"><label class="form-label">Date début *</label><input type="date" name="start_date" class="form-control" value="{{ training.start_date.isoformat() if training is defined and training.start_date else '' }}" required></div>
                <div class="col-md-6"><label class="form-label">Date fin</label><input type="date" name="end_date" class="form-control" value="{{ training.end_date.isoformat() if training is defined and training.end_date else '' }}"></div>
            </div>
            <div class="row mb-3">
                <div class="col-md-6"><label class="form-label">Heure de début</label><input type="time" name="start_time" class="form-control" value="{{ training.start_time.strftime('%H:%M') if training is defined and training.start_time else '' }}"></div>
                <div class="col-md-6"><label class="form-label">Heure de fin</label><input type="time" name="end_time" class="form-control" value="{{ training.end_time.strftime('%H:%M') if training is defined and training.end_time else '' }}"></div>
                <div class="form-text">La période bloque toute maintenance pour le participant confirmé.</div>
            </div>
            <div class="row mb-3">
                <div class="col-md-12"><label class="form-label">Lieu</label><input type="text" name="location" class="form-control" value="{{ training.location if training is defined and training.location else '' }}"></div>
            </div>
            <div class="text-end"><button type="submit" class="btn btn-primary"><i class="bi bi-check-lg"></i> {{ 'Importer et bloquer le planning' if source_interpretation is defined else 'Enregistrer' }}</button></div>
        </form>
    </div></div>
</div>
{% endblock %}
