<?php
/**
 * Rendu de templates PHP — injection de variables par extract().
 *
 * Les templates restent du PHP pur (<?= ?> pour l'échappement).
 * Aucun moteur de template, aucune compilation.
 *
 * Usage :
 *   View::display(WEBROOT_PATH . '/views/login.php', ['error' => $msg]);
 *   $html = View::render(WEBROOT_PATH . '/views/login.php', ['error' => $msg]);
 */
class View
{
    public static function render(string $templatePath, array $data = []): string
    {
        extract($GLOBALS, EXTR_SKIP);
        extract($data, EXTR_OVERWRITE);
        ob_start();
        include $templatePath;
        return ob_get_clean();
    }

    public static function display(string $templatePath, array $data = []): void
    {
        // Import bootstrap globals so templates see $i18n, $auth, etc.
        // EXTR_SKIP ensures explicit $data keys take precedence.
        extract($GLOBALS, EXTR_SKIP);
        extract($data, EXTR_OVERWRITE);
        include $templatePath;
    }
}
