<?php

namespace Modules\Admin\Countries;


class View_Utils_FormFilters extends \App\Mvc\View_Utils_FormAbstract
{

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

		// load globals
		$CFG   = \Engine\Loader_Cfg::getInstance()->getGlobal();
		$_LANG = \App\Loader_Lang::getInstance()->getAll();

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

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

		// criterion filter
		$fld = new \Engine\Form\Input\Select($this->lang['formFields']['criterion'], 'filters[criterion]', $fieldsValues['criterion']);
		$list = [];
		$list[''] = $this->lang['index']['filters']['anyCountry'];
		foreach ($CFG['countriesCriteria'] as $criterion) {
			$list[$criterion] = $_LANG['locations']['countriesCriteria']['long'][$criterion];
		}
		$fld->setPossibleValues($list);
		$form->addElement($fld);

		// code/code3 filter
		$fld = new \Engine\Form\Input\Text(sprintf("%s/%s", $this->lang['index']['filters']['code'], $this->lang['index']['filters']['code3']), 'filters[code]', $fieldsValues['code']);
		$form->addElement($fld);

		// zone filter
		$fld = new \Engine\Form\Input\Select($this->lang['formFields']['zone'], 'filters[zone]', $fieldsValues['zone']);
		$list = [];
		$list[''] = $this->lang['index']['filters']['anyCountry'];
		foreach ($CFG['countriesZones'] as $zone) {
			$list[$zone] = $_LANG['locations']['countriesZones'][$zone];
		}
		$fld->setPossibleValues($list);
		$form->addElement($fld);

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

	}

}

