<?php

declare(strict_types=1);

namespace App\Core;

final class View
{
    /** @param array<string, mixed> $data */
    public static function render(string $template, array $data = []): void
    {
        extract($data, EXTR_SKIP);
        $viewFile = dirname(__DIR__, 2) . '/views/' . $template . '.php';
        require dirname(__DIR__, 2) . '/views/admin/layout/header.php';
        require $viewFile;
        require dirname(__DIR__, 2) . '/views/admin/layout/footer.php';
    }

    /** @param array<string, mixed> $data Render without the admin chrome (login page). */
    public static function bare(string $template, array $data = []): void
    {
        extract($data, EXTR_SKIP);
        require dirname(__DIR__, 2) . '/views/' . $template . '.php';
    }

    public static function e(mixed $value): string
    {
        return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
    }
}
