<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\View\View;

class ReferralController extends Controller
{
    public function index(): View
    {
        return view('admin.referrals.index', [
            'totalReferrals' => User::query()->whereNotNull('referred_by')->count(),
            'topReferrers' => User::query()
                ->withCount('referrals')
                ->having('referrals_count', '>', 0)
                ->orderByDesc('referrals_count')
                ->take(10)
                ->get(),
            'referrals' => User::query()
                ->with('referredBy')
                ->whereNotNull('referred_by')
                ->latest()
                ->paginate(15),
        ]);
    }
}
