<?php
namespace App\Dashboard\Templates\Home;

class Sysadmin extends \App\Dashboard\Templates\BaseAbstract
{
	public function configureDashboard()
	{
		// add container to dashboard
		$t1c = new \Engine\Dashboard\Containers\Table1Col();
		$t1c->setTitle($this->getName());
		$this->dashboard->appendElement($t1c);

		// Server current info
		$serverCurrentInfo = new \App\Dashboard\Widget\ServerCurrentInfo();

		// Server load history
		$serverLoadLogs = new \App\Dashboard\Widget\ServerLoadLogs();

		// Disk free space
		$diskFreeSpace = new \App\Dashboard\Widget\DiskFreeSpace();

		// add widgets to dashboard
 		$t1c->appendElement($serverCurrentInfo, 0);
 		$t1c->appendElement($serverLoadLogs, 0);
 		$t1c->appendElement($diskFreeSpace, 0);

	}

	public function getDescription()
	{
		\App\Loader_Lang::getInstance()->loadAppFile("_customLoad/dashboard/dashboard/_general.lang.php");
		$_LANG = \App\Loader_Lang::getInstance()->getGlobal();

		$widgetNames = [];
		foreach ($this->dashboard->getContentLinear()[0]->getContentLinear() as $widget) {
			$widgetNames[] = $widget->getTitle();
		}
		$widgetNamesStr = implode(", ", $widgetNames);

		$link = \Engine\Mvc\Dispatcher::getInstance()->getAppUrl('Modules/Home', 'selectFirstTemplate', [
			'template' => addslashes('\\'.__CLASS__),
		]);

		$description = <<<HTML
			<div class="tplRow">
				<div class="tplCol">
					<img src="Modules/Home/View/_img/Sysadmin.png" onclick="requestChangeTemplate('{$link}');" style="cursor:pointer;" tooltip="{$_LANG['dashboard']['tooltips']['selectTemplate']}" />
				</div>
				<div class="tplCol">
					<a onclick="requestChangeTemplate('{$link}');" class="tplLink" href="javascript:;" tooltip="{$_LANG['dashboard']['tooltips']['selectTemplate']}">{$this->getName()}</a>

					<div class="text"><b>{$_LANG['dashboard']['templates']['general']['who']}</b></div>
					<div class="text"><b>{$_LANG['dashboard']['templates']['\\'.__CLASS__]['who']}</b></div>
					<div class="text">{$_LANG['dashboard']['templates']['\\'.__CLASS__]['description']}</div>
				</div>
			</div>
			<div class="tplRow">
				<div class="tplCol">
					<div class="text"><b>{$_LANG['dashboard']['templates']['general']['widgets']}</b></div>
					<div class="text">{$widgetNamesStr}.</div>
				</div>
			</div>
HTML;

		return $description;
	}

}
