<?php
namespace Modules\Admin\Config\ServiceClassCodeRules;

class View_Utils_FormFilters extends \App\Mvc\View_Utils_FormAbstract
{

	/**
	 * Creates the form for filters
	 * @see \App\Mvc\View_Utils_FormAbstract::getForm()
	 */
	public function getForm()
	{
		$CFG = \Engine\Loader_Cfg::getInstance()->getGlobal();
		$_LANG = \App\Loader_Lang::getInstance()->getAll();

		$fieldsValues = $this->values['listingParams']->getFilters();

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

		// service class code filter
		$nameFld=new \Engine\Form\Input\Text($this->lang['index']['filters']['classCode'], 'filters[classCode]', $fieldsValues['classCode']);
		$form->addElement($nameFld);

		// service supplier code  filter
		$codeFld = new \App\Form\Input\Autocomplete_Supplier($this->lang['index']['filters']['supplierCode'], 'filters[supplierCode]', $fieldsValues['supplierCode']);
		$form->addElement($codeFld);

		// service class name filter
		$classNameFld = new \Engine\Form\Input\Select($this->lang['index']['filters']['className'], 'filters[className]', $fieldsValues['className']);
		$values = [];

		foreach ($CFG['travel']['transportSegmentClassNames'] as $transportKey) {
			$values[$transportKey] = $_LANG['flightClass'][$transportKey];
		}

		$classNameFld->setPossibleValues( $values );
		$classNameFld->showDefaultOption();
		$classNameFld->setDefaultOptionText("-");
		$form->addElement($classNameFld);


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

}