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

class Agent 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);

		// Exchange rate
		$currencyExchangeRates = new \App\Dashboard\Widget\CurrencyExchangeRates();

		// Currency convertor
		$currencyCalculator = new \App\Dashboard\Widget\CurrencyCalculator();

		// Invoices list (filter by responsible and not issued)
		$lastInvoices = new \App\Dashboard\Widget\LastInvoices();
		$lastInvoices->setOption('userType', 'responsible');
		$lastInvoices->setOption('issued', '1');

		// Imported services (my own and not processed)
		$lastImportedServices = new \App\Dashboard\Widget\LastImportedServices();
		$lastImportedServices->setOption('responsible', 'user');
		$lastImportedServices->setOption('processStatus', ['new']);

		// add widgets to dashboard
		$t1c->appendElement($currencyExchangeRates, 0);
		$t1c->appendElement($currencyCalculator, 0);
		$t1c->appendElement($lastInvoices, 0);
		$t1c->appendElement($lastImportedServices, 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/Agent.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;
	}

}
