<?php

namespace App\Http\Controllers\User;

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

class DashboardController extends Controller
{
    public function index()
    {
        $user = auth()->user();
        $stats = [
            'invoices_unpaid' => Invoice::where('user_id', $user->id)->where('status', 'unpaid')->count(),
            'invoices_paid'   => Invoice::where('user_id', $user->id)->where('status', 'paid')->count(),
        ];
        $recent_invoices = Invoice::where('user_id', $user->id)->latest()->take(5)->get();
        $latest_blogs = Blog::published()->with('author')->latest('published_at')->take(5)->get();
        return view('user.dashboard', compact('stats', 'recent_invoices', 'latest_blogs'));
    }
}
