<?php

declare(strict_types=1);

namespace App\Livewire\Admin;

use App\Models\BlogPost;
use App\Models\ReviewedWebsite;
use App\Models\User;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Layout;
use Livewire\Component;

#[Layout('layouts.admin')]
final class Dashboard extends Component
{
    #[Computed]
    public function stats(): array
    {
        $today = now()->toDateString();

        return [
            'published_posts' => BlogPost::query()->where('status', 'published')->count(),
            'draft_posts' => BlogPost::query()->where('status', 'draft')->count(),
            'reviewed_websites' => ReviewedWebsite::query()->count(),
            'new_users_today' => User::query()->whereDate('created_at', $today)->count(),
        ];
    }

    #[Computed]
    public function recentPosts()
    {
        return BlogPost::query()
            ->with('category')
            ->latest()
            ->limit(5)
            ->get();
    }

    public function render()
    {
        return view('livewire.admin.dashboard');
    }
}
