<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\Buku;
use App\Models\Anggota;
use App\Models\Peminjaman;

class DashboardController extends Controller
{
    public function index()
    {
        $bukuPopuler = Buku::withCount('peminjaman')
                           ->orderBy('peminjaman_count', 'desc')
                           ->take(5)
                           ->get();

        $totalBuku = Buku::count();
        $totalAnggota = Anggota::count();
        $totalPeminjamanHariIni = Peminjaman::whereDate('tanggal_pinjam', now()->toDateString())->count();

        return view('admin.index', compact('totalBuku', 'totalAnggota', 'totalPeminjamanHariIni', 'bukuPopuler'));
    }
}
