<?php

declare(strict_types=1);

namespace Lab;

final class View
{
    /** @param array<string, mixed> $data */
    public static function render(string $template, array $data = []): void
    {
        extract($data, EXTR_SKIP);
        $config = $GLOBALS['lab_config'] ?? require dirname(__DIR__) . '/config.php';
        $appName = $config['app_name'] ?? 'Panorama Lab';
        $business = $config['business'] ?? [];

        require dirname(__DIR__) . '/views/' . $template . '.php';
    }

    public static function redirect(string $path): never
    {
        if (! str_starts_with($path, 'http://') && ! str_starts_with($path, 'https://')) {
            $path = Helpers::url($path);
        }
        header('Location: ' . $path, true, 303);
        exit;
    }
}
