{% extends "base.html" %}

{% block title %}Home{% endblock %}

{% block content %}
<div class="row mb-4">
    <div class="col-12">
        <h3 class="text-muted mb-4">
            {{ data_atual }}
        </h3>
    </div>
</div>

<div class="row g-4">
    {% if current_user.has_permission('view_cell_data') %}
    <!-- Card de Militantes -->
    <div class="col-md-6 col-lg-3">
        <div class="card bg-primary text-white">
            <div class="card-body">
                <div class="d-flex justify-content-between align-items-center">
                    <div>
                        <h6 class="card-title mb-0">Total de Militantes</h6>
                        <h2 class="my-2">{{ total_militantes }}</h2>
                    </div>
                    <div class="fs-1">
                        <i class="fas fa-users"></i>
                    </div>
                </div>
                <a href="{{ url_for('listar_militantes') }}" class="text-white text-decoration-none">
                    Ver detalhes <i class="fas fa-arrow-right ms-1"></i>
                </a>
            </div>
        </div>
    </div>
    {% endif %}

    {% if current_user.has_permission('view_cell_reports') %}
    <!-- Card de Cotas -->
    <div class="col-md-6 col-lg-3">
        <div class="card bg-success text-white">
            <div class="card-body">
                <div class="d-flex justify-content-between align-items-center">
                    <div>
                        <h6 class="card-title mb-0">Total de Cotas</h6>
                        <h2 class="my-2">R$ {{ total_cotas }}</h2>
                    </div>
                    <div class="fs-1">
                        <i class="fas fa-dollar-sign"></i>
                    </div>
                </div>
                <a href="{{ url_for('listar_cotas') }}" class="text-white text-decoration-none">
                    Ver detalhes <i class="fas fa-arrow-right ms-1"></i>
                </a>
            </div>
        </div>
    </div>

    <!-- Card de Materiais -->
    <div class="col-md-6 col-lg-3">
        <div class="card bg-info text-white">
            <div class="card-body">
                <div class="d-flex justify-content-between align-items-center">
                    <div>
                        <h6 class="card-title mb-0">Materiais Vendidos</h6>
                        <h2 class="my-2">{{ total_materiais }}</h2>
                    </div>
                    <div class="fs-1">
                        <i class="fas fa-book"></i>
                    </div>
                </div>
                <a href="{{ url_for('listar_materiais') }}" class="text-white text-decoration-none">
                    Ver detalhes <i class="fas fa-arrow-right ms-1"></i>
                </a>
            </div>
        </div>
    </div>

    <!-- Card de Assinaturas -->
    <div class="col-md-6 col-lg-3">
        <div class="card bg-warning text-white">
            <div class="card-body">
                <div class="d-flex justify-content-between align-items-center">
                    <div>
                        <h6 class="card-title mb-0">Assinaturas Ativas</h6>
                        <h2 class="my-2">{{ total_assinaturas }}</h2>
                    </div>
                    <div class="fs-1">
                        <i class="fas fa-newspaper"></i>
                    </div>
                </div>
                <a href="{{ url_for('listar_assinaturas') }}" class="text-white text-decoration-none">
                    Ver detalhes <i class="fas fa-arrow-right ms-1"></i>
                </a>
            </div>
        </div>
    </div>
    {% endif %}
</div>

<div class="row mt-4">
    {% if current_user.has_permission('view_cell_data') %}
    <!-- Últimos Militantes -->
    <div class="col-md-6 mb-4">
        <div class="card h-100">
            <div class="card-header bg-light">
                <h5 class="card-title mb-0">
                    <i class="fas fa-user-plus me-2"></i>Últimos Militantes Cadastrados
                </h5>
            </div>
            <div class="card-body">
                {% if ultimos_militantes %}
                <div class="list-group list-group-flush">
                    {% for militante in ultimos_militantes %}
                    <a href="{{ url_for('editar_militante', id=militante.id) }}" class="list-group-item list-group-item-action">
                        <div class="d-flex w-100 justify-content-between">
                            <h6 class="mb-1">{{ militante.nome }}</h6>
                            <small class="text-muted">{{ militante.created_at.strftime('%d/%m/%Y') }}</small>
                        </div>
                        <small class="text-muted">{{ militante.email }}</small>
                    </a>
                    {% endfor %}
                </div>
                {% else %}
                <p class="text-muted mb-0">Nenhum militante cadastrado recentemente.</p>
                {% endif %}
            </div>
        </div>
    </div>
    {% endif %}

    {% if current_user.has_permission('view_cell_reports') %}
    <!-- Últimos Pagamentos -->
    <div class="col-md-6 mb-4">
        <div class="card h-100">
            <div class="card-header bg-light">
                <h5 class="card-title mb-0">
                    <i class="fas fa-money-bill-wave me-2"></i>Últimos Pagamentos
                </h5>
            </div>
            <div class="card-body">
                {% if ultimos_pagamentos %}
                <div class="list-group list-group-flush">
                    {% for pagamento in ultimos_pagamentos %}
                    <div class="list-group-item">
                        <div class="d-flex w-100 justify-content-between">
                            <h6 class="mb-1">{{ pagamento.militante.nome }}</h6>
                            <span class="badge bg-success">R$ {{ "%.2f"|format(pagamento.valor) }}</span>
                        </div>
                        <small class="text-muted">{{ pagamento.data_pagamento.strftime('%d/%m/%Y') }}</small>
                    </div>
                    {% endfor %}
                </div>
                {% else %}
                <p class="text-muted mb-0">Nenhum pagamento registrado recentemente.</p>
                {% endif %}
            </div>
        </div>
    </div>
    {% endif %}
</div>
{% endblock %} 