<?php

namespace Modules\Admin\Config\Balances\Numbers;

class View_Utils_FormAdmin extends \App\Mvc\View_Utils_FormAbstract
{

	/**
	 * Creates the form for department insert/update.
	 * @see \App\Mvc\View_Utils_FormAbstract::getForm()
	 */
	public function getForm()
	{
		$balanceNumberObj = \App\Config\OrderNumber::getInstance();
		$allowedResetCriteria = $balanceNumberObj->getAllowedCriteria();
		$numberMaxLength = $balanceNumberObj->getAllowedNumberMaxLength();

		///////////////////////////////////////////////////////////////////////////////////////////////////
		// DEFINE THE FORM ////////////////////////////////////////////////////////////////////////////////
		///////////////////////////////////////////////////////////////////////////////////////////////////

		// INITIALIZE THE FORM ////////////////////////////////////////////////////////////////////////////
		$form = \Engine\Form\General::create();
		$formContainer = \Engine\Form\Container\Fieldset::create($this->lang['index']['fieldset']);
		$form->addContainer($formContainer);
		$form->setStyle('width', 300);

		// CRITERIA FOR BALANCES RESET /////////////////////////////////////////////////////////////////
		$fld = new \Engine\Form\Input\Checkboxes($this->lang['index']['fields']['criteria'], 'criteria', $this->values['criteria']);
		$criteriaFields = [];

		foreach($allowedResetCriteria as $crit) {
			$criteriaFields[$crit] = "<strong>".$this->lang['index']['fields']['criteriaLabels'][$crit]."</strong> ".$this->lang['index']['fields']['criteriaLabelDesc'][$crit];
		}
		$fld->setPossibleValues($criteriaFields);
		$fld->setStyle('renderMode', 'block');
		$fld->setDetails($this->lang['index']['fieldsDescriptions']['criteria']);
		$formContainer->addElement($fld);

		// BALANCES NUMBER LENGTH //////////////////////////////////////////////////////////////////////
		$fld = new \Engine\Form\Input\Text($this->lang['index']['fields']['length'], 'numberLength', $this->values['numberLength']);
		$fld->setValidator(['type'=>'int', 'minValue'=>0, 'maxValue'=>$numberMaxLength]);
		$fld->setDetails($this->lang['index']['fieldsDescriptions']['length'] );
		$formContainer->addElement($fld);

		//Preparing descriptions for prefix and suffix
		$prefixAndSuffixValues = "<b>{idUser}</b>, <b>{userRemark:variableName}</b>, <b>{idDepartment}</b>, <b>{departmentCode}</b>,  <b>{idOffice}</b>, <b>{officeIataCode}</b>,  <b>{officeName}</b>, <b>{year}</b>,  <b>{month}</b>,  <b>{day}</b>";
		$prefixAndSuffixInfo = sprintf($this->lang['index']['fieldsDescriptions']['prefixAndSuffix'], $prefixAndSuffixValues);

		// BALANCES NUMBER PREFIX //////////////////////////////////////////////////////////////////////
		$fld = new \Engine\Form\Input\Text($this->lang['index']['fields']['prefix'], 'prefix', $this->values['prefix']);
		$fld->setDetails($this->lang['index']['fieldsDescriptions']['prefix'].' '.$prefixAndSuffixInfo);
		$formContainer->addElement($fld);

		// BALANCES NUMBER SUFFIX //////////////////////////////////////////////////////////////////////
		$fld = new \Engine\Form\Input\Text($this->lang['index']['fields']['suffix'], 'suffix', $this->values['suffix']);
		$fld->setDetails($this->lang['index']['fieldsDescriptions']['suffix'].' '.$prefixAndSuffixInfo);
		$formContainer->addElement($fld);


		$formContainer->addElement(new \Engine\Form\Input\Hidden(null, 'save', 1));
		$form->addButton(new \Engine\Form\Button\Submit('save'));

		return $form;
	}
}