<?php

namespace App\Livewire\Admin;

use App\Enums\UserStatus;
use App\Models\AgentLog;
use App\Models\User;
use Livewire\Component;

class Dashboard extends Component
{
    public function render()
    {
        return view('livewire.admin.dashboard', [
            'totalUsers'       => User::count(),
            'activeUsers'      => User::where('status', UserStatus::Active)->count(),
            'newThisMonth'     => User::where('created_at', '>=', now()->startOfMonth())->count(),
            'proUsers'         => User::whereHas('subscription', fn($q) => $q->where('status', 'active'))->count(),
            'totalCreditsUsed' => AgentLog::where('created_at', '>=', now()->startOfMonth())->sum('credits'),
            'totalCost'        => AgentLog::where('created_at', '>=', now()->startOfMonth())->sum('cost_usd'),
            'recentLogs'       => AgentLog::with('user')->latest()->limit(10)->get(),
        ])->layout('layouts.app');
    }
}
