{% extends "base.html" %}
{% block title %}Calendrier - GMAO{% endblock %}
{% block content %}
<div class="container-fluid">
    <h2 class="h4 mb-3"><i class="bi bi-calendar3"></i> Calendrier des interventions</h2>
    
    <!-- Navigation -->
    <div class="d-flex justify-content-between align-items-center mb-3">
        <a href="{{ url_for('scheduler.calendar', month=prev_month.month, year=prev_month.year) }}" class="btn btn-outline-secondary btn-sm">
            <i class="bi bi-chevron-left"></i> Precedent
        </a>
        <strong>{{ month_name }} {{ year }}</strong>
        <a href="{{ url_for('scheduler.calendar', month=next_month.month, year=next_month.year) }}" class="btn btn-outline-secondary btn-sm">
            Suivant <i class="bi bi-chevron-right"></i>
        </a>
    </div>

    <!-- Grille calendrier -->
    <div class="card border-0 shadow-sm">
        <div class="card-body p-2">
            <div class="row text-center fw-bold mb-1" style="font-size:0.8rem;">
                {% for day_name in ['Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam', 'Dim'] %}
                <div class="col">{{ day_name }}</div>
                {% endfor %}
            </div>
            {% for week in weeks %}
            <div class="row g-1 mb-1">
                {% for day in week %}
                <div class="col" style="min-height:80px; {% if not day %}background:#f8f9fa;{% endif %}">
                    {% if day %}
                    <div class="border rounded p-1 h-100 {% if day['is_today'] %}border-primary border-2{% endif %}" style="min-height:75px; font-size:0.7rem;">
                        <div class="fw-bold {% if day['is_today'] %}text-primary{% endif %}">{{ day['day'] }}</div>
                        {% for item in day['items'] %}
                        <div class="badge bg-{{ item.color }} d-block text-truncate mb-1" title="{{ item.title }}">
                            {{ item.start_time }} {{ item.title[:20] if item.title else '' }}
                        </div>
                        {% endfor %}
                    </div>
                    {% endif %}
                </div>
                {% endfor %}
            </div>
            {% endfor %}
        </div>
    </div>

    <!-- Legende -->
    <div class="mt-2" style="font-size:0.8rem;">
        <span class="badge bg-primary">Preventif</span>
        <span class="badge bg-danger">Curatif</span>
        <span class="badge bg-warning text-dark">Admin</span>
        <span class="badge bg-info">Information</span>
    </div>
</div>
{% endblock %}