<?php
namespace Modules\Admin\OfferProfileRules;

class View_Utils_FormFilters extends \App\Mvc\View_Utils_FormAbstract
{
	public function getForm()
	{
		$fieldsValues = $this->values['listingParams']->getFilters();

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

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

		// active
		$fld_active = new \Engine\Form\Input\Select($this->lang['index']['filters']['active'], 'filters[active]', $fieldsValues['active']);
		$fld_active->setPossibleValues([
			'all' => 		$this->lang['active']['default'],
			'active' => 	$this->lang['active']['true'],
			'inactive' => 	$this->lang['active']['false'],
		]);
		$form->addElement($fld_active);

		// fee rule id
		$fld_feeRuleId = new \Engine\Form\Input\Text($this->lang['index']['filters']['feeRuleId'], 'filters[id]', $fieldsValues['id']);
		$form->addElement($fld_feeRuleId);

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

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

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

		// client type
		$fld_clientType = new \Engine\Form\Input\Select($this->lang['index']['filters']['clientType'], 'filters[clientType]', $fieldsValues['clientType']);
		$fld_clientType->setPossibleValues( [''=>$this->lang['index']['filters']['clientTypeAll'], 'default'=>$this->lang['index']['filters']['clientTypeDefault']] );
		$form->addElement($fld_clientType);

		// service code
		$fld_serviceCode = new \App\Form\Input\Select_Service($this->lang['index']['filters']['serviceCode'], 'filters[serviceCode]', $fieldsValues['serviceCode']);
		$form->addElement($fld_serviceCode);

		// offer components
		$fld_offerComponents = new \Engine\Form\Input\Select($this->lang['index']['filters']['offerComponents'], 'filters[offerComponents]', $fieldsValues['offerComponents']);
		$fld_offerComponents->setPossibleValues([
			'includeCommission' => 	$this->lang['offerComponents']['includeCommission'],
			'includeDiscount' => 	$this->lang['offerComponents']['includeDiscount'],
			'includeServiceFee' => 	$this->lang['offerComponents']['includeServiceFee'],
			]);
		$fld_offerComponents->showDefaultOption();
		$form->addElement($fld_offerComponents);

		// validity date
		$fld_validityPeriod = new \Engine\Form\Input\DateInterval($this->lang['index']['filters']['validity'], 'filters[validity]', $fieldsValues['validity']);
		$form->addElement($fld_validityPeriod);

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