<?php

namespace Modules\Admin\Config\Services\ActiveServices;

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()
	{

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


		// NEW FORM ///////////////////////////////////////////////////////////////////////////////////////

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


		// LOOP THROUGH EACH SERVICE ----------------------------------------------------------------------
		$otherServicesFieldset = null;
		foreach (\App\Config\Services_Basic::getInstance()->getListGrouped() as $groupServiceCode => $groupServiceDetails) {

			if($groupServiceDetails['type']=='group') {
				$fieldset = \Engine\Form\Container\Fieldset::create($groupServiceDetails['name']) ;
				$form->addContainer($fieldset);
				foreach($groupServiceDetails['list'] as $serviceCode=>$serviceDetails) {

					$checkbox = new \App\Form\Input\Checkboxes_CountryCriterion($serviceDetails['name'], 'activeServices['.$serviceCode.']', $this->values['activeServices'][$serviceCode]);
					$fieldset->addElement($checkbox);
				}

			}
			else {
				if (!$otherServicesFieldset) {
					$otherServicesFieldset = \Engine\Form\Container\Fieldset::create($this->lang['index']['fieldset']['otherSection']);
				}
				$checkbox = new \App\Form\Input\Checkboxes_CountryCriterion($groupServiceDetails['name'], 'activeServices['.$groupServiceCode.']', $this->values['activeServices'][$groupServiceCode]);
				$otherServicesFieldset->addElement($checkbox);
			}
		}
		if ($otherServicesFieldset) {
			$form->addContainer($otherServicesFieldset);
		}

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

		return $form;
	}
}