<?php
namespace Modules\Admin\Config\Gds\Profiles\Fields;

class View_Utils_FormFilters extends \App\Mvc\View_Utils_FormAbstract
{

	/**
	 * Creates the form for fields 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);

		// category
		$fld = new \Engine\Form\Input\Select($this->lang['index']['filters']['category'], 'filters[category]', $fieldsValues['category']);
		$fld->setPossibleValues([
				'corporate' => $this->lang['index']['categories']['corporate'],
				'customer' => $this->lang['index']['categories']['customer'],
		]);
		$fld->showDefaultOption();
		$form->addElement($fld);

		// type
		$fld = new \Engine\Form\Input\Select($this->lang['index']['filters']['type'], 'filters[type]', $fieldsValues['type']);
		$fld->setPossibleValues([
				'static'  => $this->lang['index']['types']['static'],
				'dynamic' => $this->lang['index']['types']['dynamic'],
		]);
		$fld->showDefaultOption();
		$form->addElement($fld);

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

		// inputType
		$fld = new \Engine\Form\Input\Select($this->lang['index']['filters']['inputType'], 'filters[inputType]', $fieldsValues['inputType']);
		$fld->setPossibleValues([
			'text' 		=> $this->lang['formFields']['inputTypes']['text'],
			'textarea' 	=> $this->lang['formFields']['inputTypes']['textarea'],
			'radio' 	=> $this->lang['formFields']['inputTypes']['radio'],
			'select' 	=> $this->lang['formFields']['inputTypes']['select'],
			//'checkbox' 	=> $this->lang['formFields']['inputTypes']['checkbox'],
			//'date' 		=> $this->lang['formFields']['inputTypes']['date'],
		]);
		$fld->showDefaultOption();
		$form->addElement($fld);

		// idProfileTemplate
		$listObj = new \App\EntityList\GdsProfilesTemplates();
		$listObj->setColumns(['name', 'category']);
		$listObj->setOrderBy('name', 'ASC');
		$tpls = $listObj->exportRecords();

		$values = [];
		foreach ($tpls as $tpl) {
			$values[$tpl['id']] = sprintf("%s (%s)", $tpl['name'], $this->lang['index']['categories'][$tpl['category']]);
		}
		$fld = new \Engine\Form\Input\Select($this->lang['index']['filters']['idProfileTemplate'], 'filters[idProfileTemplate]', $fieldsValues['idProfileTemplate']);
		$fld->setPossibleValues($values);
		$fld->showDefaultOption();
		$form->addElement($fld);

		// GDS
		$fld = new \Engine\Form\Input\Select($this->lang['index']['filters']['gds'], 'filters[gds]', $fieldsValues['gds']);
		$fld->setPossibleValues([
				'amadeus' => 'Amadeus',
				'sabre' => 'Sabre',
				'galileo' => 'Galileo',
				'worldspan' => 'Worldspan',
				'apollo' => 'Apollo',

		]);
		$fld->showDefaultOption();
		$form->addElement($fld);

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

	}

}
