<?php
namespace Modules\Admin\Config\Gds\Galileo;

class View_Utils_FormAdmin extends \App\Mvc\View_Utils_FormAbstract
{

	/**
	 * (non-PHPdoc)
	 * @see \App\Mvc\View_Utils_FormAbstract::getForm()
	 */
	public function getForm()
	{
		$form=\Engine\Form\General::create();
		$form->setStyle('width', '300');

		// add container
		$fieldset = \Engine\Form\Container\Fieldset::create('');
		$form->addContainer($fieldset);

		// importPassengerEmail
		$importPassengerEmail = new \Engine\Form\Input\Select($this->lang['index']['formFields']['importPassengerEmail'], 'importPassengerEmail', $this->values['importPassengerEmail'], [
			'' => 				$this->globalLang['no'],
			'fromA12' => 		$this->lang['index']['formFields']['importPassengerEmail_fromA12Line'],
		]);
		$fieldset->addElement($importPassengerEmail);


		// importPassengerEmail_ignoredAddresses
		$importPassengerEmail_ignoredAddresses = new \Engine\Form\Input\Cloned_Text($this->lang['index']['formFields']['importPassengerEmail_ignoredAddresses'], 'importPassengerEmail_ignoredAddresses', $this->values['importPassengerEmail_ignoredAddresses']);
		$importPassengerEmail_ignoredAddresses->setDetails($this->lang['index']['formFields']['importPassengerEmail_ignoredAddresses_']);
		$fieldset->addElement($importPassengerEmail_ignoredAddresses);

		// importPassengerTelephone
		$importPassengerTelephone = new \Engine\Form\Input\Select($this->lang['index']['formFields']['importPassengerTelephone'], 'importPassengerTelephone', $this->values['importPassengerTelephone'], [
				'' => 				$this->globalLang['no'],
				'fromA12PHN' => 	$this->lang['index']['formFields']['importPassengerTelephone_fromA12PHN'],
		]);
		$fieldset->addElement($importPassengerTelephone);


		// importPassengerTelephone_ignoredPhoneNumbers
		$importPassengerTelephone_ignoredPhoneNumbers = new \Engine\Form\Input\Cloned_Text($this->lang['index']['formFields']['importPassengerTelephone_ignoredPhoneNumbers'], 'importPassengerTelephone_ignoredPhoneNumbers', $this->values['importPassengerTelephone_ignoredPhoneNumbers']);
		$importPassengerTelephone_ignoredPhoneNumbers->setDetails($this->lang['index']['formFields']['importPassengerTelephone_ignoredPhoneNumbers_']);
		$fieldset->addElement($importPassengerTelephone_ignoredPhoneNumbers);

		// set controlled elements
		$importPassengerEmail->setControlledElements([
			'' => [$importPassengerEmail_ignoredAddresses],
		], 'enable');

		$importPassengerTelephone->setControlledElements([
			'' => [$importPassengerTelephone_ignoredPhoneNumbers],
		], 'enable');

		$ignoreSupplierOnDocuments = new \Engine\Form\Input\KeyValueCheckboxes($this->lang['index']['formFields']['ignoreSupplierOnDocuments'], 'ignoreSupplierOnDocuments', $this->values['ignoreSupplierOnDocuments']);
		$ignoreSupplierOnDocuments->setDetails($this->lang['index']['formFields']['ignoreSupplierOnDocuments_']);
		$ignoreSupplierOnDocuments->setAssociationsList([
			'ticketing'	=>				'Ticketing',
			'EMD' => 					'EMD',
			'MCO' => 					'MCO',
			'reissue'	=>				'Reissue',
			'car' => 					'Car',
			'hotel'	=>					'Hotel',
			'surface' => 				'Surface',
			'LCCTicketing' => 			'LCC Ticketing',
			'NDCTicketing' => 			'NDC Ticketing',
		]);
		$ignoreSupplierOnDocuments->setPossibleValues([
			'' => 					'unset',
			'cash' => 				'cash',
			'CC' => 				'CC',
			'cheque'	=>			'cheque',
			'exchange'	=>			'exchange',
			'invoice'	=>			'invoice',
			'NON REFUNDABLE'	=>	'NON REFUNDABLE',
			'MULTIPLE'	=>			'MULTIPLE',
			'FREE'	=>				'FREE',
			'misc'	=>				'misc',
		]);
		$ignoreSupplierOnDocuments->setStyle('highlight', 'current_if_set');
		$fieldset->addElement($ignoreSupplierOnDocuments);


		// importServiceFeeForService & importServiceFeeForServiceCurrency
		$importCurrencyPossibleValues = [
			'serviceFeeCurrency' => 'remark serviceFeeCurrency',
		];
		foreach (\App\Config\Currencies::getInstance()->getSimple() as $c) {
			$importCurrencyPossibleValues[$c] = sprintf("force to %s", $c);
		}

		$serviceFeeContainer = new \Engine\Form\Input\ElementWithElements($this->lang['index']['formFields']['importServiceFeeForService'], null, []);
		$serviceFeeContainer->addElement(
			\Engine\Form\Input\Select::create(null, 'importServiceFeeForService', $this->values['importServiceFeeForService'], [
				'' => 				$this->globalLang['no'],
				'all' => 			$this->lang['index']['formFields']['importServiceFeeForService_all'],
				'ticketing,EMD' =>	$this->lang['index']['formFields']['importServiceFeeForService_ticketingAndEmd'],
				'ticketing' => 		$this->lang['index']['formFields']['importServiceFeeForService_ticketing'],
			])
			, 'main' );
		$serviceFeeContainer->addElement(
			\Engine\Form\Input\Select::create(null, 'importServiceFeeForServiceCurrency', $this->values['importServiceFeeForServiceCurrency'], $importCurrencyPossibleValues)
		, 'post');
		$serviceFeeContainer->setStyle('renderMode', 'inline');
		$fieldset->addElement($serviceFeeContainer);


		// importDiscountForService & importDiscountForServiceCurrency
		$importCurrencyPossibleValues = [
			'discountCurrency' => 'remark discountCurrency',
		];
		foreach (\App\Config\Currencies::getInstance()->getSimple() as $c) {
			$importCurrencyPossibleValues[$c] = sprintf("force to %s", $c);
		}
		$serviceFeeContainer = new \Engine\Form\Input\ElementWithElements($this->lang['index']['formFields']['importDiscountForService'], null, []);
		$serviceFeeContainer->addElement(
			\Engine\Form\Input\Select::create(null, 'importDiscountForService', $this->values['importDiscountForService'], [
				'' => 				$this->globalLang['no'],
				'all' => 			$this->lang['index']['formFields']['importDiscountForService_all'],
			])
			, 'main' );
		$serviceFeeContainer->addElement(
			\Engine\Form\Input\Select::create(null, 'importDiscountForServiceCurrency', $this->values['importDiscountForServiceCurrency'], $importCurrencyPossibleValues)
		, 'post');
		$serviceFeeContainer->setStyle('renderMode', 'inline');
		$fieldset->addElement($serviceFeeContainer);


		// importCommissionForService & importCommissionForServiceCurrency
		$importCurrencyPossibleValues = [
			'commissionCurrency' => 'remark commissionCurrency',
		];
		foreach (\App\Config\Currencies::getInstance()->getSimple() as $c) {
			$importCurrencyPossibleValues[$c] = sprintf("force to %s", $c);
		}
		$commissionContainer = new \Engine\Form\Input\ElementWithElements($this->lang['index']['formFields']['importCommissionForService'], null, []);
		$commissionContainer->addElement(
			\Engine\Form\Input\Select::create(null, 'importCommissionForService', $this->values['importCommissionForService'], [
				'' => 				$this->globalLang['no'],
				'ticketing' => 		$this->lang['index']['formFields']['importCommissionForService_ticketing'],
				'all' => 			$this->lang['index']['formFields']['importCommissionForService_all'],
			])
			, 'main' );
		$commissionContainer->addElement(
			\Engine\Form\Input\Select::create(null, 'importCommissionForServiceCurrency', $this->values['importCommissionForServiceCurrency'], $importCurrencyPossibleValues)
		, 'post');
		$commissionContainer->setStyle('renderMode', 'inline');
		$fieldset->addElement($commissionContainer);


		// vat percent
		$CFG = \Engine\Loader_Cfg::getInstance()->getGlobal();
		$vatPercent = new \App\Form\Input\MultipliedText($this->lang['index']['formFields']['vatPercent'], 'vatPercent', $this->values['vatPercent']);
		$vatPercent->setMultiplier(count($CFG['countriesCriteria']));
		$vatPercent->setMultiplierLabelKeys($CFG['countriesCriteria']);
		$vatPercent->setMultiplierLabels($CFG['countriesCriteria']);
		$vatPercent->setStyle('CSSClass', 'input-multipliedElementLabelTop');
		$vatPercent->setMultiplierLabelVisibility(true);
		$vatPercent->setValidatorParam('minValue', 0);
		$vatPercent->setValidatorParam('maxValue', 100);
		$vatPercent->setValidatorParam('type', 'float');
		$fieldset->addElement($vatPercent);

		// the submit button
		$form->addElement(new \Engine\Form\Input\Hidden(null, $this->submitButtonName, 1));

		// submit button
		$form->addButton(new \Engine\Form\Button\Submit('save'));

		return $form;
	}

}
