{% extends "base.html" %}
{% block title %}Mes congés — GMAO Collège{% endblock %}

{% block content %}
<div class="py-2 py-md-3">
  <div class="d-flex justify-content-between align-items-center mb-3">
    <h2 class="mb-0 h5"><i class="bi bi-person-dash"></i> Mes congés</h2>
    <div class="d-flex gap-1">
      <a href="{{ url_for('planning.index') }}" class="btn btn-sm btn-outline-secondary"><i class="bi bi-arrow-left"></i></a>
      <a href="{{ url_for('planning.leave_add') }}" class="btn btn-sm btn-primary"><i class="bi bi-plus-lg"></i> <span class="d-none d-sm-inline">Ajouter</span></a>
    </div>
  </div>

  <!-- À venir -->
  {% if upcoming %}
  <h6 class="text-muted mb-2"><i class="bi bi-calendar-event"></i> À venir</h6>
  {% for l in upcoming %}
  <div class="card border-0 shadow-sm mb-2">
    <div class="card-body py-2 px-3">
      <div class="d-flex justify-content-between align-items-start">
        <div>
          <strong>{{ l.label }}</strong>
          <div class="small text-muted">{{ l.start_date|date_fmt }} → {{ l.end_date|date_fmt }} <span class="badge bg-light text-dark">{{ l.duration_days }}j</span></div>
          {% if l.am_only %}<small class="text-info">Matin seulement</small>{% endif %}
          {% if l.pm_only %}<small class="text-info">Après-midi seulement</small>{% endif %}
        </div>
        <span class="badge {% if l.type == 'maladie' %}bg-danger{% elif l.type == 'conges_personnel' %}bg-info{% elif l.type == 'formation' %}bg-success{% else %}bg-secondary{% endif %}" style="font-size:0.7rem;">{{ l.type_label }}</span>
      </div>
      {% if l.notes %}<small class="text-muted d-block mt-1">{{ l.notes }}</small>{% endif %}
      <form method="POST" action="{{ url_for('planning.leave_delete', id=l.id) }}" class="mt-1" onsubmit="return confirm('Supprimer ce congé ?')">
        <button type="submit" class="btn btn-sm btn-outline-danger py-0" style="font-size:0.7rem;"><i class="bi bi-trash"></i></button>
      </form>
    </div>
  </div>
  {% endfor %}
  {% endif %}

  <!-- Passés -->
  {% if past %}
  <h6 class="text-muted mb-2 mt-3"><i class="bi bi-calendar-check"></i> Passés</h6>
  {% for l in past %}
  <div class="card border-0 shadow-sm mb-1 opacity-50">
    <div class="card-body py-1 px-3">
      <div class="d-flex justify-content-between">
        <small>{{ l.label }}</small>
        <small class="text-muted">{{ l.start_date|date_fmt }} → {{ l.end_date|date_fmt }}</small>
      </div>
    </div>
  </div>
  {% endfor %}
  {% endif %}

  {% if not upcoming and not past %}
  <div class="text-center py-5 text-muted">
    <i class="bi bi-calendar-x" style="font-size:2rem;"></i>
    <p class="mt-2">Aucun congé enregistré</p>
    <a href="{{ url_for('planning.leave_add') }}" class="btn btn-sm btn-primary"><i class="bi bi-plus-lg"></i> Ajouter un congé</a>
  </div>
  {% endif %}
</div>
{% endblock %}