<?php

use domain\User\User\User;
use domain\User\User\UserModule;

function version(string $date, array $featuresMaintenanceArray, array $featuresMaintenanceAdminArray, User $userCurrent) {
    release_date($date);
    features($featuresMaintenanceArray[0] ?? [], $featuresMaintenanceAdminArray[0] ?? [], $userCurrent);
    maintenance($featuresMaintenanceArray[1] ?? [], $featuresMaintenanceAdminArray[1] ?? [], $userCurrent);
}

function release_date(string $date) {
    $html = '<div class="block block-release-date">';
    $html .= '<h4><span class="glyphicon glyphicon-calendar"></span>  Date de sortie</h4>';
    $html .= '<ul><li>'.$date.'</li></ul>';
    $html .= '</div>';
    echo $html;
}

function features(array $featuresArray, array $featuresAdminArray, User $userCurrent) {
    $userModule = UserModule::getInstance();
    $isGrantedAsUserCurrent = $userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userCurrent);
    if(count($featuresArray) > 0 || (count($featuresAdminArray) > 0 && $isGrantedAsUserCurrent)) {
        $html = '<div class="block block-features">';
        $html .= '<h4><span class="glyphicon glyphicon-flash"></span> Évolutions</h4>';
        $html .= '<ul>';
        foreach($featuresArray as $feature) {
            $html .= '<li>'.$feature.'</li>';
        }
        if($isGrantedAsUserCurrent) {
            foreach($featuresAdminArray as $feature) {
                $html .= '<li class="admin">'.$feature.'</li>';
            }
        }
        $html .= '</ul>';
        $html .= '</div>';
        echo $html;
    }
}

function maintenance(array $maintenanceArray, array $maintenanceAdminArray, User $userCurrent) {
    $userModule = UserModule::getInstance();
    if(count($maintenanceArray) > 0 || count($maintenanceAdminArray) > 0) {
        $html = '<div class="block block-maintenance">';
        $html .= '<h4><span class="glyphicon glyphicon-wrench"></span> Maintenance</h4>';
        $html .= '<ul>';
        foreach($maintenanceArray as $maintenance) {
            $html .= '<li>'.$maintenance.'</li>';
        }
        if($userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userCurrent)) {
            foreach ($maintenanceAdminArray as $maintenance) {
                $html .= '<li class="admin">' . $maintenance . '</li>';
            }
        }
        $html .= '</ul>';
        $html .= '</div>';
        echo $html;
    }
}