<?php
/// file: app/Controllers/Admin/DashboardController.php

declare(strict_types=1);

namespace App\Controllers\Admin;

use App\Core\Controller;
use App\Core\Request;
use App\Core\Response;

final class DashboardController extends Controller
{
    public function index(Request $request): Response
    {
        $pdo = $this->app->pdo();
        $stats = [
            'projects' => (int) $pdo->query('SELECT COUNT(*) FROM projects')->fetchColumn(),
            'journal' => (int) $pdo->query('SELECT COUNT(*) FROM journal_posts')->fetchColumn(),
            'contacts' => (int) $pdo->query("SELECT COUNT(*) FROM contact_submissions WHERE status = 'new'")->fetchColumn(),
            'applications' => (int) $pdo->query("SELECT COUNT(*) FROM job_applications WHERE status = 'new'")->fetchColumn(),
        ];
        $html = $this->adminView('admin/dashboard', ['stats' => $stats]);
        return Response::html($html);
    }
}
