<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\User;
use App\Models\LeasingRecord;
use App\Models\ManualPayment;
use App\Models\AuditLog;
use Illuminate\Http\Request;

class DashboardController extends Controller
{
    public function index()
    {
        $stats = [
            'total_leasing' => User::whereHas('role', fn($q) => $q->where('name', 'leasing'))->count(),
            'total_member' => User::whereHas('role', fn($q) => $q->where('name', 'member'))->count(),
            'pending_payments' => ManualPayment::where('payment_status', 'pending')->count(),
            'total_records' => LeasingRecord::count(),
        ];

        $recentLogs = AuditLog::with('user')->latest()->take(10)->get();

        return view('admin.dashboard', compact('stats', 'recentLogs'));
    }
}
