<?php

declare(strict_types=1);

namespace Core;

final class View
{
    public static function render(string $view, array $data = [], string $layout = 'app'): void
    {
        extract($data);
        $viewPath = dirname(__DIR__) . '/app/Views/' . $view . '.php';
        $layoutPath = dirname(__DIR__) . '/app/Views/layouts/' . $layout . '.php';

        ob_start();
        require $viewPath;
        $content = ob_get_clean();
        require $layoutPath;
    }

    public static function renderToString(string $view, array $data = []): string
    {
        extract($data);
        $viewPath = dirname(__DIR__) . '/app/Views/' . $view . '.php';
        ob_start();
        require $viewPath;
        return (string) ob_get_clean();
    }
}
