<?php

namespace FluxCms\Core\Http\Controllers\Admin;

use FluxCms\Core\Models\BlogPost;
use FluxCms\Core\Models\Page;
use Illuminate\Routing\Controller;

class DashboardController extends Controller
{
    public function __invoke()
    {
        $stats = [
            'pages' => Page::count(),
            'published_pages' => Page::published()->count(),
            'draft_pages' => Page::where('is_published', false)->count(),
            'blog_posts' => BlogPost::count(),
            'published_posts' => BlogPost::published()->count(),
        ];

        $recentPages = Page::with(['components'])
            ->orderBy('updated_at', 'desc')
            ->limit(5)
            ->get();

        return view('flux-cms::admin.dashboard', compact('stats', 'recentPages'));
    }
}
