{% extends "base.html" %}

{% block title %}Outlook Debug - GMAO Collège{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="row mb-4">
        <div class="col">
            <h1>📧 Outlook Debug Interface</h1>
            <p class="text-muted">Interface de test - Tous les boutons et tokens sont visibles</p>
        </div>
        <div class="col-auto">
            <a href="{{ url_for('outlook_test.add_account') }}" class="btn btn-primary">
                <i class="fas fa-plus"></i> Ajouter un compte
            </a>
        </div>
    </div>

    <!-- Liste des comptes -->
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h5 class="mb-0">Comptes Outlook (mode debug)</h5>
                </div>
                <div class="card-body">
                    {% if accounts %}
                        <div class="table-responsive">
                            <table class="table table-striped table-sm">
                                <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>Email</th>
                                        <th>Tenant ID</th>
                                        <th>Refresh Token (DEBUG)</th>
                                        <th>Statut</th>
                                        <th>Actif</th>
                                        <th>Créé le</th>
                                        <th>Actions</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for account in accounts %}
                                    <tr>
                                        <td><code>{{ account.id }}</code></td>
                                        <td><code>{{ account.email }}</code></td>
                                        <td><code>{{ account.tenant_id }}</code></td>
                                        <td style="font-size: 0.8em;"><code>{{ account.refresh_token[:50] }}...</code></td>
                                        <td><code>{{ account.connection_status }}</code></td>
                                        <td><code>{{ account.is_active }}</code></td>
                                        <td><code>{{ account.created_at }}</code></td>
                                        <td>
                                            <a href="{{ url_for('outlook_test.sync_raw', account_id=account.id) }}" class="btn btn-sm btn-outline-success" title="Sync raw">
                                                <i class="fas fa-sync"></i>
                                            </a>
                                            <a href="{{ url_for('outlook_test.latest_mail', account_id=account.id) }}" class="btn btn-sm btn-outline-primary" title="Dernier mail">
                                                <i class="fas fa-envelope"></i>
                                            </a>
                                            <a href="{{ url_for('outlook_test.delete_account', account_id=account.id) }}" class="btn btn-sm btn-outline-danger" title="Supprimer" onclick="return confirm('Supprimer ce compte ?')">
                                                <i class="fas fa-trash"></i>
                                            </a>
                                        </td>
                                    </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                        </div>
                    {% else %}
                        <div class="text-center py-4">
                            <i class="fas fa-envelope fa-3x text-muted mb-3"></i>
                            <h5>Aucun compte configuré</h5>
                            <a href="{{ url_for('outlook_test.add_account') }}" class="btn btn-primary">
                                <i class="fas fa-plus"></i> Ajouter un premier compte
                            </a>
                        </div>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}