<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\Instansi;
use App\Models\Karyawan;
use App\Models\Absensi;

class DashboardController extends Controller
{
    public function index()
    {
        $totalInstansi       = Instansi::count();
        $totalKaryawan       = Karyawan::count();
        $totalAbsensiHariIni = Absensi::whereDate('tanggal', today())
                                ->whereNotNull('jam_masuk')->count();

        $instansiList = Instansi::withCount('karyawans')
                            ->latest()->get();

        return view('admin.dashboard', compact(
            'totalInstansi',
            'totalKaryawan',
            'totalAbsensiHariIni',
            'instansiList'
        ));
    }
}