<?php

namespace AleshaCMS\Http\Controllers\Admin;

use AleshaCMS\Http\Controllers\Controller;
use AleshaCMS\Models\Post;
use AleshaCMS\Models\User;

class DashboardController extends Controller
{
    public function index()
    {
        $stats = [
            'posts' => Post::where('content_type', 'post')->count(),
            'pages' => Post::where('content_type', 'page')->count(),
            'users' => User::count(),
            'drafts' => Post::where('status', 'draft')->count(),
        ];

        $recentPosts = Post::with('author')
            ->latest()
            ->take(5)
            ->get();

        return view('admin.dashboard', compact('stats', 'recentPosts'));
    }
}
