<?php

namespace Modules\Admin\Config\ClientInvoices\TotalRounding;

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()
	{
		$_LANG = \App\Loader_Lang::getInstance()->getAll();
		$form = \Engine\Form\General::create();

		$label = new \Engine\Form\Input\Label();
		$label->setDetails($this->lang['index']['description']);
		$form->addElement($label);

		// active option /////////////////////////////////////////////////////////////////////////
		$fieldsetActive = \Engine\Form\Container\Fieldset::create($this->lang['legends']['active']);
		$form->addContainer($fieldsetActive);

		// create checkboxes for active option
		$fld = new \Engine\Form\Input\Radio($this->lang['content']['activeOpt'], 'active', $this->values['active']);
		$fld->setPossibleValues(['0' => $_LANG['no'], '1' => $_LANG['yes']]);
		$fieldsetActive->addElement($fld);

		// ROUNDING TYPE  ////////////////////////////////////////////////////////////////////////////////////
		$fieldsetRound = \Engine\Form\Container\Fieldset::create($this->lang['legends']['rounding']);
		$form->addContainer($fieldsetRound);
		$possibleValuesOfRoundType = [
				'round' => $this->lang['roundTypes']['round'],
				'floor' => $this->lang['roundTypes']['floor'],
				'ceil'  => $this->lang['roundTypes']['ceil']
		];
		$radioRoundType = new \Engine\Form\Input\Radio($this->lang['formDefinitions']['formFields']['roundType'], 'roundType', $this->values['roundType'], $possibleValuesOfRoundType);
		$radioRoundType->setTooltip($this->lang['explanations']['roundingType']);
		$radioRoundType->setMandatory();
		$fieldsetRound->addElement($radioRoundType);

		// SERVICES////////////////////////////////////////////////////////////////////////////////////////
		$fieldsetService = \Engine\Form\Container\Fieldset::create($this->lang['legends']['blockedServices']);
		$form->addContainer($fieldsetService);

		// list of services
		foreach (\App\Config\Services_Basic::getInstance()->getListLinear() as $serviceCode => $serviceDetails) {
			$possibleValuesOfServices[$serviceCode] = $serviceDetails['name'];
		}

		// create checkboxes for blocked services
		$checkboxesService = new \Engine\Form\Input\Checkboxes($this->lang['content']['serviceCantRound'], 'blockedServices', $this->values['blockedServices'], $possibleValuesOfServices);
		$checkboxesService->setTooltip($this->lang['explanations']['blockedServices']);
		$checkboxesService->setStyle('renderMode', 'aligned');
		$fieldsetService->addElement($checkboxesService);

		// CURRENCIES /////////////////////////////////////////////////////////////////////////////
		$fieldsetCurrency = \Engine\Form\Container\Fieldset::create($this->lang['legends']['currencies']);
		$form->addContainer($fieldsetCurrency);

		// list of currencies
		foreach (\App\Config\Currencies::getInstance()->getSimple() as $currencyCode) {
			$possibleValuesOfCurrecies[$currencyCode] = $currencyCode;
		}
		// create checkboxes for currecies
		$checkboxesCurrency = new \Engine\Form\Input\Checkboxes($this->lang['content']['currencyDefaultRounded'], 'defaultByCurrency', $this->values['defaultByCurrency'], $possibleValuesOfCurrecies);
		$checkboxesCurrency->setTooltip($this->lang['explanations']['currencies']);
		$fieldsetCurrency->addElement($checkboxesCurrency);

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

		return $form;
	}
}