<?php
namespace nur\v\html5;

use nur\b\UserException;
use nur\v\base\AbstractPage;
use nur\v\http;
use nur\v\model\IErrorPage;
use nur\v\page;
use nur\v\vo;

class Html5BasicErrorPage extends AbstractPage implements IErrorPage {
  function __construct(...$vs) {
    foreach ($vs as &$v) {
      $v = q($v);
    }; unset($v);
    $this->vs = $vs;
  }

  protected $vs;

  function printError(): void {
    $error = $this->getError();
    $message = $error["message"];
    if (!$message) $message = $this->vs;
    if (!$message) $message = "Une erreur inattendue s'est produite";
    vo::p(["class" => "error-message", q($message)]);
    $exception = $error["exception"];
    if ($exception) {
      vo::pre(["class" => "error-exception",
        q(UserException::get_summary($exception)), "\n",
        q(UserException::get_traceback($exception)),
      ]);
    }
  }

  function print(): void {
    page::no_cache();
    http::error500(null, null, false);
    $this->printError();
  }
}