import os
import platform
from django.shortcuts import render
from django.utils import timezone
from .models import Letter, Student

def index(request):
    """Render the SIMSBI dashboard."""
    now = timezone.now()
    
    # Simple stats
    total_letters = Letter.objects.count()
    letters_in = Letter.objects.filter(type='IN').count()
    letters_out = Letter.objects.filter(type='OUT').count()
    total_students = Student.objects.count()
    
    recent_letters = Letter.objects.all().order_by('-created_at')[:5]
    
    context = {
        "project_name": "SIMSBI",
        "total_letters": total_letters,
        "letters_in": letters_in,
        "letters_out": letters_out,
        "total_students": total_students,
        "recent_letters": recent_letters,
        "current_time": now,
    }
    return render(request, "core/index.html", context)