{% extends "base.html" %}
{% block title %}Export Interventions - GMAO{% endblock %}
{% block content %}
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-3">
        <h1 class="h3"><i class="bi bi-file-earmark-pdf"></i> Export des interventions</h1>
        <div>
            <a href="{{ url_for('exports.export_interventions_csv', status=filters.status) }}" class="btn btn-success btn-sm">
                <i class="bi bi-file-earmark-spreadsheet"></i> CSV
            </a>
            <button onclick="window.print()" class="btn btn-primary btn-sm">
                <i class="bi bi-printer"></i> Imprimer / PDF
            </button>
            <a href="{{ url_for('dashboard.index') }}" class="btn btn-secondary btn-sm">
                <i class="bi bi-arrow-left"></i> Retour
            </a>
        </div>
    </div>

    <div class="card mb-3">
        <div class="card-body">
            <p><strong>Genere le :</strong> {{ generated_at|datetime_fmt }}</p>
            <p><strong>Filtres :</strong>
                {% if filters.status %} Statut={{ filters.status }} {% endif %}
                {% if filters.from %} Du={{ filters.from }} {% endif %}
                {% if filters.to %} Au={{ filters.to }} {% endif %}
                {% if not filters.status and not filters.from and not filters.to %} Aucun (toutes){% endif %}
            </p>
            <p><strong>Total :</strong> {{ interventions|length }} intervention(s)</p>
        </div>
    </div>

    <div class="card">
        <div class="card-body">
            <table class="table table-striped table-sm">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Titre</th>
                        <th>Type</th>
                        <th>Statut</th>
                        <th>Priorite</th>
                        <th>Date creation</th>
                        <th>Equipement</th>
                        <th>Salle</th>
                    </tr>
                </thead>
                <tbody>
                    {% for i in interventions %}
                    <tr>
                        <td>{{ i.id }}</td>
                        <td>{{ i.title }}</td>
                        <td>{{ i.type }}</td>
                        <td>{{ i.status }}</td>
                        <td>{{ i.priority }}</td>
                        <td>{{ i.created_at|datetime_fmt if i.created_at else '' }}</td>
                        <td>{{ i.equipment.name if i.equipment else '' }}</td>
                        <td>{{ i.room.name if i.room else '' }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>

<style>
@media print {
    .navbar, .btn, .card-header { display: none !important; }
    body { background: white !important; }
    .card { border: 1px solid #000 !important; box-shadow: none !important; }
}
</style>
{% endblock %}