<?php

namespace App\Http\Controllers\SuperAdmin;

use App\Http\Controllers\Controller;
use App\Models\School;
use App\Models\User;
use Illuminate\Http\Request;

class DashboardController extends Controller
{
    public function index()
    {
        $totalSchools = School::count();
        $totalTeachers = User::where('role', 'teacher')->count();
        $totalStudents = User::where('role', 'student')->count();
        $totalRevenue = 58200; // Placeholder - we'll make this real in Finance module later

        // Recent Schools (last 5)
        $recentSchools = School::latest()->take(5)->get();

        // Schools by Type for Chart
        $schoolsByType = School::selectRaw('type, count(*) as count')
            ->groupBy('type')
            ->pluck('count', 'type');

        return view('superadmin.dashboard', compact(
            'totalSchools', 
            'totalTeachers', 
            'totalStudents', 
            'totalRevenue',
            'recentSchools',
            'schoolsByType'
        ));
    }
}