<?php

namespace App\Http\Controllers\Reseller;

use App\Http\Controllers\Controller;
use App\Models\Blog;
use App\Models\Invoice;

class DashboardController extends Controller
{
    public function index()
    {
        $user = auth()->user();
        $stats = [
            'blogs_total'     => Blog::where('user_id', $user->id)->count(),
            'blogs_views'     => Blog::where('user_id', $user->id)->sum('views'),
            'blogs_quota'     => $user->blogs_quota,
            'blogs_used'      => $user->blogs_used,
            'blogs_remaining' => $user->blogsRemaining(),
            'invoices_unpaid' => Invoice::where('user_id', $user->id)->where('status', 'unpaid')->count(),
        ];
        $recent_blogs = Blog::where('user_id', $user->id)->latest()->take(5)->get();
        $recent_invoices = Invoice::where('user_id', $user->id)->latest()->take(5)->get();

        return view('reseller.dashboard', compact('stats', 'recent_blogs', 'recent_invoices'));
    }
}
