{% extends "base.html" %}

{% block title %}Comptes Outlook{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1 class="h3 mb-0">Comptes Outlook</h1>
        <div class="btn-group">
            <a href="{{ url_for('outlook_dashboard.context_config') }}" class="btn btn-outline-primary">
                <i class="bi bi-gear"></i> Contexte GMAO
            </a>
            <a href="{{ url_for('outlook_pages.add_account') }}" class="btn btn-primary">
                <i class="bi bi-plus-lg"></i> Ajouter un compte
            </a>
        </div>
    </div>
    
    <div class="alert alert-info mb-4" role="alert">
        <i class="bi bi-info-circle"></i>
        <strong>Contexte GMAO :</strong> Configurez le contexte utilisé par Hermes pour interpréter vos emails.
        <a href="{{ url_for('outlook_dashboard.context_config') }}" class="alert-link">Accéder à la configuration &rarr;</a>
    </div>
    
    {% if accounts %}
    <div class="table-responsive">
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>Email</th>
                    <th>Statut</th>
                    <th>Dernière connexion</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
                {% for account in accounts %}
                <tr>
                    <td>{{ account.email }}</td>
                    <td>
                        {% if account.connection_status == 'active' %}
                        <span class="badge bg-success">Actif</span>
                        {% elif account.connection_status == 'pending' %}
                        <span class="badge bg-warning">En attente</span>
                        {% else %}
                        <span class="badge bg-secondary">{{ account.connection_status or 'Inconnu' }}</span>
                        {% endif %}
                    </td>
                    <td>{{ account.last_connected_at|datetime_fmt if account.last_connected_at else '-' }}</td>
                    <td>
                        <a href="{{ url_for('outlook_pages.account_detail', account_id=account.id) }}" class="btn btn-sm btn-info">
                            <i class="bi bi-envelope"></i> Emails
                        </a>
                        <form action="{{ url_for('outlook_pages.delete_account', account_id=account.id) }}" method="POST" style="display:inline;" onsubmit="return confirm('Supprimer ce compte Outlook ?');">
                            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                            <button type="submit" class="btn btn-sm btn-danger">
                                <i class="bi bi-trash"></i> Supprimer
                            </button>
                        </form>
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
    {% else %}
    <div class="alert alert-info">Aucun compte Outlook configuré.</div>
    {% endif %}
</div>
{% endblock %}