<?php
namespace Modules\Admin\Config\Services\Attributes;

class View_Utils_Edit extends \App\Mvc\View_Utils_FormAbstract
{

	/**
	 * (non-PHPdoc)
	 * @see \App\Mvc\View_Utils_FormAbstract::getForm()
	 */
	public function getForm()
	{

		$form = \Engine\Form\General::create();

		$fieldsetCategory = \Engine\Form\Container\Fieldset::create($this->lang['edit']['legends']['category']);
		$form->addContainer($fieldsetCategory);

		// TYPE
		$inputCategoryType = new \Engine\Form\Input\Select($this->lang['edit']['formFields']['type'], 'category[type]', $this->values['category']['type']);
		$inputCategoryType->setTooltip($this->lang['edit']['formTooltip']['category']);
		$inputCategoryType->setPossibleValues([
			'' 			=> $this->lang['types']['choose'],
			'none' 		=> $this->lang['types']['none'],
			'text' 		=> $this->lang['types']['text'],
			'list' 		=> $this->lang['types']['list']
		]);
		$inputCategoryType->setMandatory();
		$fieldsetCategory->addElement($inputCategoryType);

		// ELEMENTS (ITEMS)
		$inputCategoryElements = new \App\Form\Input\Cloned_KeyValue($this->lang['edit']['formFields']['items'], 'category[list]', $this->values['category']['list']);
		$inputCategoryElements->setCodeMaxlength(1);
		$inputCategoryElements->setMandatory();
		$fieldsetCategory->addElement($inputCategoryElements);


		// FIELD NAME
		$inputCategoryFieldName = new \Engine\Form\Input\Text($this->lang['edit']['formFields']['fieldName'], 'category[fieldName]', $this->values['category']['fieldName']);
		$fieldsetCategory->addElement($inputCategoryFieldName);

		// CONTROLLED ELEMENTS
		$inputCategoryType->setControlledElements(
			[
				'text' 	=> [$inputCategoryFieldName],
				'list' 	=> [$inputCategoryElements, $inputCategoryFieldName],
			],
			'hide'
		);

		///////////////////////////////////////////////////////////////////////////////////////////
		// PRODUCT NAME ///////////////////////////////////////////////////////////////////////////
		///////////////////////////////////////////////////////////////////////////////////////////

		$fieldsetProductName = \Engine\Form\Container\Fieldset::create($this->lang['edit']['legends']['productName']);
		$form->addContainer($fieldsetProductName);

		// TYPE
		$inputProductNameType = new \Engine\Form\Input\Select($this->lang['edit']['formFields']['type'], 'productName[type]', $this->values['productName']['type']);
		$inputProductNameType->setPossibleValues(
			[
				'' 				=> $this->lang['types']['choose'],
				'none' 			=> $this->lang['types']['none'],
				'text' 			=> $this->lang['types']['text'],
				'autocomplete' 	=> $this->lang['types']['autocomplete'],
				'both' 			=> $this->lang['types']['both']
			]
		);
		$inputProductNameType->setMandatory();
		$fieldsetProductName->addElement($inputProductNameType);

		// FIELD NAME
		$inputProductNameFieldName = new \Engine\Form\Input\Text($this->lang['edit']['formFields']['fieldName'], 'productName[fieldName]', $this->values['productName']['fieldName']);
		$fieldsetProductName->addElement($inputProductNameFieldName);

		// CONTROLLED ELEMENTS
		$inputProductNameType->setControlledElements(
			[
				'text' 			=> [$inputProductNameFieldName],
				'autocomplete'	=> [$inputProductNameFieldName],
				'both' 			=> [$inputProductNameFieldName]
			],
			'hide'
		);


		///////////////////////////////////////////////////////////////////////////////////////////
		// PRODUCT TYPE ///////////////////////////////////////////////////////////////////////////
		///////////////////////////////////////////////////////////////////////////////////////////

		$fieldsetProductType = \Engine\Form\Container\Fieldset::create($this->lang['edit']['legends']['productType']);
		$form->addContainer($fieldsetProductType);

		// TYPE
		$inputProductType_Type = new \Engine\Form\Input\Select($this->lang['edit']['formFields']['type'], 'productType[type]', $this->values['productType']['type']);
		$inputProductType_Type->setTooltip($this->lang['edit']['formTooltip']['productType']);
		$inputProductType_Type->setPossibleValues(
			[
				'' 		=> $this->lang['types']['choose'],
				'none' 	=> $this->lang['types']['none'],
				'text' 	=> $this->lang['types']['text'],
				'list' 	=> $this->lang['types']['list'],
			]
		);
		$inputProductType_Type->setMandatory();
		$fieldsetProductType->addElement($inputProductType_Type);

		// ELEMENTS (ITEMS)
		$inputProductTypeElements = new \App\Form\Input\Cloned_KeyValue($this->lang['edit']['formFields']['items'], 'productType[list]', $this->values['productType']['list']);
		$inputProductTypeElements->setCodeMaxlength(1);
		$inputProductTypeElements->setMandatory();
		$fieldsetProductType->addElement($inputProductTypeElements);

		// FIELD NAME
		$inputProductTypeFieldName = new \Engine\Form\Input\Text($this->lang['edit']['formFields']['fieldName'], 'productType[fieldName]', $this->values['productType']['fieldName']);
		$fieldsetProductType->addElement($inputProductTypeFieldName);

		// CONTROLLED ELEMENTS
		$inputProductType_Type->setControlledElements(
			[
				'text' 		=> [$inputProductTypeFieldName],
				'list'		=> [$inputProductTypeElements, $inputProductTypeFieldName],
			],
			'hide'
		);


		///////////////////////////////////////////////////////////////////////////////////////////
		// MULTIPLIER /////////////////////////////////////////////////////////////////////////////
		///////////////////////////////////////////////////////////////////////////////////////////
		$fieldsetMultiplier = \Engine\Form\Container\Fieldset::create($this->lang['edit']['legends']['productMultiplier']);
		$form->addContainer($fieldsetMultiplier);

		// TYPE
		$inputMultiplierType = new \Engine\Form\Input\Select($this->lang['edit']['formFields']['type'], 'productMultiplier[type]', $this->values['productMultiplier']['type']);
		$inputMultiplierType->setTooltip($this->lang['edit']['formTooltip']['productMultiplier']);
		$inputMultiplierType->setPossibleValues(
			[
				'' 		=> $this->lang['types']['choose'],
				'none' 	=> $this->lang['types']['none'],
				'value'	=> $this->lang['types']['value'],
				'list' 	=> $this->lang['types']['list']
			]
		);
		$inputMultiplierType->setMandatory();
		$fieldsetMultiplier->addElement($inputMultiplierType);

		// ELEMENTS (ITEMS)
		$inputMultiplierElements = new \App\Form\Input\Cloned_KeyValue($this->lang['edit']['formFields']['items'], 'productMultiplier[list]', $this->values['productMultiplier']['list']);
		$inputMultiplierElements->setCodeMaxlength(1);
		$inputMultiplierElements->setMandatory();
		$fieldsetMultiplier->addElement($inputMultiplierElements);

		// FIELD NAME
		$inputMultiplierFieldName = new \Engine\Form\Input\Text($this->lang['edit']['formFields']['fieldName'], 'productMultiplier[fieldName]', $this->values['productMultiplier']['fieldName']);
		$fieldsetMultiplier->addElement($inputMultiplierFieldName);

		// CONTROLLED ELEMENTS
		$inputMultiplierType->setControlledElements(
			[
				'value'	=> [$inputMultiplierFieldName],
				'list' 	=> [$inputMultiplierElements, $inputMultiplierFieldName]
			],
			'hide'
		);


		///////////////////////////////////////////////////////////////////////////////////////////
		// SERVICE SOURCE /////////////////////////////////////////////////////////////////////////
		///////////////////////////////////////////////////////////////////////////////////////////

		$fieldsetServiceSource = \Engine\Form\Container\Fieldset::create($this->lang['edit']['legends']['serviceSource']);
		$form->addContainer($fieldsetServiceSource);

		// TYPE
		$inputServiceSourceType = new \Engine\Form\Input\Select($this->lang['edit']['formFields']['type'], 'serviceSource[type]', $this->values['serviceSource']['type']);
		$inputServiceSourceType->setTooltip($this->lang['edit']['formTooltip']['serviceSource']);
		$inputServiceSourceType->setPossibleValues(
			[
				'' 		=> $this->lang['types']['choose'],
				'none' 	=> $this->lang['types']['none'],
				'text' 	=> $this->lang['types']['text'],
				'list' 	=> $this->lang['types']['list'],
			]
		);
		$inputServiceSourceType->setMandatory();
		$fieldsetServiceSource->addElement($inputServiceSourceType);

		// ELEMENTS (ITEMS)
		$inputServiceSourceElements = new \App\Form\Input\Cloned_KeyValue($this->lang['edit']['formFields']['items'], 'serviceSource[list]', $this->values['serviceSource']['list']);
		$inputServiceSourceElements->setCodeMaxlength(1);
		$inputServiceSourceElements->setMandatory();
		$fieldsetServiceSource->addElement($inputServiceSourceElements);

		// FIELD NAME
		$inputServiceSourceFieldName = new \Engine\Form\Input\Text($this->lang['edit']['formFields']['fieldName'], 'serviceSource[fieldName]', $this->values['serviceSource']['fieldName']);
		$fieldsetServiceSource->addElement($inputServiceSourceFieldName);

		// CONTROLLED ELEMENTS
		$inputServiceSourceType->setControlledElements(
			[
				'text' 	=> [$inputServiceSourceFieldName],
				'list' 	=> [$inputServiceSourceElements, $inputServiceSourceFieldName],
			],
			'hide'
		);

		$form->addElement(new \Engine\Form\Input\Hidden('', $this->submitButtonName, 1));

		return $form;
	}

}