from django.contrib.auth.decorators import login_required
from django.shortcuts import render
from django.contrib.auth.models import User
from django.contrib.sessions.models import Session
from core.models import Report
from django.utils.timezone import now



@login_required
def index_view(request):
    total_users = User.objects.count()
    total_reports = Report.objects.count()
    total_sessions = Session.objects.filter(expire_date__gt=now()).count()
    latest_reports = Report.objects.order_by('-created_at')[:25]

    return render(request, 'dashboard/index.html', {
        'total_users': total_users,
        'total_reports': total_reports,
        'total_sessions': total_sessions,
        'latest_reports': latest_reports,
    })
