<?php

declare(strict_types=1);

namespace App\Modules\Administration\Controllers;

use App\Controllers\Controller;
use App\Modules\Administration\Services\AuthenticationService;
use App\Modules\Administration\Services\DashboardService;
use System\View\View;

final class DashboardController extends Controller
{
    public function __construct(
        private AuthenticationService $authentication,
        private DashboardService $dashboardService,
        View $view
    ) {
        parent::__construct($view);
    }

    public function index(): void
    {
        if (!$this->authentication->check()) {

            header(
                'Location: /public/login'
            );

            exit;
        }

        $statistics =
            $this->dashboardService->statistics();

        $this->render(
            'dashboard/index',
            array_merge(
                [
                    'title' => 'Administration Dashboard',

                    'fullName' =>
                        $_SESSION['full_name'] ?? '',

                    'username' =>
                        $_SESSION['username'] ?? '',
                ],
                $statistics
            )
        );
    }
}