<?php

namespace Modules\Admin\Server\Logs;


class View_Utils_FormFilters extends \App\Mvc\View_Utils_FormAbstract
{

	/**
	 * Creates the form for logs filter
	 * @see \App\Mvc\View_Utils_FormAbstract::getForm()
	 */
	public function getForm()
	{
		$fieldsValues = $this->values['listingParams']->getFilters();

		// create form
		$form = \Engine\Form\Filters::create();
		$form->setColumns(2);
		$form->showResetButton(true);

		// text filter
		$fld = new \Engine\Form\Input\Text($this->lang['index']['filters']['text'], 'filters[text]', $fieldsValues['text']);
		$fld->setTooltip($this->lang['index']['filters']['tooltips']['text']);
		$form->addElement($fld);

		// stacktrace filter
		$fld = new \Engine\Form\Input\Text($this->lang['index']['filters']['stacktrace'], 'filters[stacktrace]', $fieldsValues['stacktrace']);
		$form->addElement($fld);

		// session filter
		$fld = new \Engine\Form\Input\Text($this->lang['index']['filters']['logSession'], 'filters[logSession]', $fieldsValues['logSession']);
		$form->addElement($fld);

		// user filter
		$fld = new \App\Form\Input\Autocomplete_User($this->lang['index']['filters']['idUser'], 'filters[idUser]', $fieldsValues['idUser']);
		$form->addElement($fld);

		// level filter
		$fld = new \Engine\Form\Input\Checkboxes($this->lang['index']['filters']['logLevel'], 'filters[logLevel]', $fieldsValues['logLevel']);
		$list = [];
		foreach (['critical', 'error', 'warning', 'info'] as $level) {
			$list[$level] = $this->lang['logLevels'][$level];
		}
		$fld->setPossibleValues($list);
		$form->addElement($fld);

		// date filter
		$fld = new \Engine\Form\Input\DatetimeInterval($this->lang['index']['filters']['addTime'], 'filters[addTime]', $fieldsValues['addTime']);
		$form->addElement($fld);


		// source filter
		$fld = new \Engine\Form\Input\Select($this->lang['index']['filters']['source'], 'filters[source]', $fieldsValues['source']);
		$fld->showDefaultOption();
		$fld->setPossibleValues([
			'TINALogger' => 'TINA',
			'FluxInstance' => 'FluX',
			'Disk' => 'Disk',
		]);
		$form->addElement($fld);

		// source filter
		$fld = new \Engine\Form\Input\Select($this->lang['index']['filters']['dataSource'], 'filters[dataSource]', $fieldsValues['dataSource']);
		$fld->setPossibleValues([
			'current' => 	$this->lang['index']['filters']['dataSource_current'],
			'archive' => 	$this->lang['index']['filters']['dataSource_archive'],
		]);
		$form->addElement($fld);

		$form->setJsCallback('MVC.listing.installedHandlers["listing"].reloadAndResetListing');
		$form->loadMissingDefaultValues($this->values['listingParams']->getDefaultFilters());
		return $form;

	}

}

