{% extends 'base.html' %}

{% block title %}Dashboard Administrativo{% endblock %}

{% block content %}
<div class="container">
    <h1 class="mb-4">Dashboard Administrativo</h1>
    
    {% with messages = get_flashed_messages(with_categories=true) %}
        {% if messages %}
            {% for category, message in messages %}
                <div class="alert alert-{{ category }}">{{ message }}</div>
            {% endfor %}
        {% endif %}
    {% endwith %}
    
    <div class="card mb-4">
        <div class="card-header">
            <h5 class="card-title mb-0">Gerenciamento de Usuários</h5>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>Usuário</th>
                            <th>Email</th>
                            <th>Admin</th>
                            <th>OTP Configurado</th>
                            <th>Ações</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for usuario in usuarios %}
                        <tr>
                            <td>{{ usuario.id }}</td>
                            <td>{{ usuario.username }}</td>
                            <td>{{ usuario.email }}</td>
                            <td>
                                {% if usuario.is_admin %}
                                    <span class="badge bg-success">Sim</span>
                                {% else %}
                                    <span class="badge bg-secondary">Não</span>
                                {% endif %}
                            </td>
                            <td>
                                {% if usuario.otp_secret %}
                                    <span class="badge bg-success">Sim</span>
                                {% else %}
                                    <span class="badge bg-danger">Não</span>
                                {% endif %}
                            </td>
                            <td>
                                <form action="{{ url_for('reset_otp', user_id=usuario.id) }}" method="POST" class="d-inline">
                                    <button type="submit" class="btn btn-warning btn-sm" 
                                            onclick="return confirm('Tem certeza que deseja resetar o OTP deste usuário?')">
                                        Resetar OTP
                                    </button>
                                </form>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    
    <div class="card">
        <div class="card-header">
            <h5 class="card-title mb-0">Ações Rápidas</h5>
        </div>
        <div class="card-body">
            <div class="d-grid gap-2">
                <a href="{{ url_for('novo_usuario') }}" class="btn btn-primary">
                    Criar Novo Usuário
                </a>
            </div>
        </div>
    </div>
</div>
{% endblock %} 