<?php
namespace Modules\Admin\QcRules;

class View_Utils_FormFilters extends \App\Mvc\View_Utils_FormAbstract
{
	/**
	 * Creates the form for document series filters.
	 * @see \App\Mvc\View_Utils_FormAbstract::getForm()
	 */
	public function getForm()
	{
		$fieldsValues = $this->values['listingParams']->getFilters();

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

		// type
		$entityFld = new \Engine\Form\Input\Select($this->lang['index']['filters']['entity'], 'filters[entity]', $fieldsValues['entity']);
		$possibleVals = [];
		foreach($this->globalCfg['qcRules']['entities'] as $ent=>$nada) {
			$possibleVals[$ent] = $this->globalLang['QcRules']['entities'][$ent];
		}
		$entityFld->setPossibleValues($possibleVals);
		$entityFld->showDefaultOption();
		$form->addElement($entityFld);

		// status
		$statusFld = new \Engine\Form\Input\Select($this->lang['index']['filters']['status'], 'filters[status]', $fieldsValues['status']);
		$statusesList = [
			"active" => 	$this->lang['index']['status']['activeFilter'],
			"inactive" => 	$this->lang['index']['status']['inactiveFilter'],
		];
		$statusFld->showDefaultOption();
		$statusFld->setPossibleValues($statusesList);
		$form->addElement($statusFld);

		// name of rule
		$nameOfRule = new \Engine\Form\Input\Text($this->lang['index']['filters']['nameOfRule'], 'filters[nameOfRule]', $fieldsValues['nameOfRule']);
		$form->addElement($nameOfRule);

		// corporation
		$corporate = new \App\Form\Input\Autocomplete_Corporate($this->lang['index']['filters']['corporate'], 'filters[corporate]', $fieldsValues['corporate']);
		$form->addElement($corporate);

		// trust
		$trust = new \App\Form\Input\Autocomplete_CorporateTrust($this->lang['index']['filters']['trust'], 'filters[trust]', $fieldsValues['trust']);
		$form->addElement($trust);

		// segment
		$segment = new \App\Form\Input\Select_CorporateSegment($this->lang['index']['filters']['segment'], 'filters[segment]', $fieldsValues['segment']);
		$segment->showDefaultOption();
		$form->addElement($segment);

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