<?php

namespace Modules\Admin\Config\ImportedOrders\Services\Attributes;

class View_Utils_FormAdmin extends \App\Mvc\View_Utils_FormAbstract
{

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

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

		$fieldset = \Engine\Form\Container\Fieldset::create($this->lang['fieldsets']['main']);
		$form->addContainer($fieldset);

		// let's make sure all attributes are assigned to possible attributes. If not, we unset the 'key'
		$attributes = $this->values['attributes'];
		if(!empty($attributes)) {
			foreach($attributes as $key => $values) {
				if (!array_key_exists($values['key'], $this->values['notCategorizedPossibleAttributesList'])) {
					$attributes[$key]['key'] = '';
				}
			}
		}

		$this->values['attributes'] = $attributes;



		$attributesFld = \App\Form\Input\Cloned_KeyValueTextSelector::create($this->lang['labels']['attribute']['general'], "attributes", $this->values['attributes']);

		$attributesFld->setSelectValues($this->values['possibleAttributesList']);
		$attributesFld->showDefaultOption();

		// set element labels
		$elementLabels = [
			'value' => $this->lang['labels']['attribute']['externalCode'],
			'key' => '',
		];

		$attributesFld->setElementLabels($elementLabels);

		$fieldset->addElement($attributesFld);

		$form->addElement(new \Engine\Form\Input\Hidden('', 'idSystem', $this->values['idSystem']));
		$form->addElement(new \Engine\Form\Input\Hidden('', 'idExternalService', $this->values['idExternalService']));


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

		return $form;
	}
}