<?php

use MintyPHP\Buffer;
use MintyPHP\Service\Access\OperationsAuthorizationPolicy;
use MintyPHP\Service\System\SystemHealthService;
use MintyPHP\Support\Guard;

Guard::requireAbilityOrForbidden(OperationsAuthorizationPolicy::ABILITY_ADMIN_SYSTEM_INFO_VIEW);

$checks = app(SystemHealthService::class)->runAll();

$overall = 'ok';
foreach ($checks as $check) {
    if ($check['status'] === 'fail') {
        $overall = 'fail';
        break;
    }
    if ($check['status'] === 'warn') {
        $overall = 'warn';
    }
}

$environment = 'unknown';
if (defined('APP_ENV')) {
    $environment = (string) constant('APP_ENV');
} else {
    $envVar = getenv('APP_ENV');
    if (is_string($envVar) && $envVar !== '') {
        $environment = $envVar;
    }
}

$meta = [
    'php_version' => PHP_VERSION,
    'environment' => $environment,
];

$lastChecked = date('Y-m-d H:i:s');

Buffer::set('title', t('System status'));

$breadcrumbs = [
    ['label' => t('Home'), 'path' => 'admin'],
    ['label' => t('System status')],
];
