<?php

namespace ModulesGarden\HostingQuotaNotifications\App\UI\Groups\Forms\Configuration;

use ModulesGarden\HostingQuotaNotifications\App\UI\Validators\GroupNameExist;
use ModulesGarden\HostingQuotaNotifications\App\UI\Validators\NotEmptyWithTrim;
use ModulesGarden\HostingQuotaNotifications\App\UI\Validators\PositiveNumber;
use \ModulesGarden\HostingQuotaNotifications\Core\UI\Widget\Forms\Fields;
use \ModulesGarden\HostingQuotaNotifications\Core\UI\Widget\Forms\Sections;
use \ModulesGarden\HostingQuotaNotifications\App\Libs\Groups;
use \ModulesGarden\HostingQuotaNotifications\App\Helper\Request;
use \ModulesGarden\HostingQuotaNotifications\App\Helper\Models\EmailTemplates;
/**
 * Description of ConfigurationForm
 *
 * @author Artur Pilch <artur.pi@modulesgarden.com>
 */
class ConfigurationForm
{
    private $section;

    public function __construct($section = false)
    {
        $this->section = new Sections\BaseSection();
        $this->section->setId('editGroupSection');
    }

    public function initFields()
    {
        $field = new Fields\Switcher('status');
        $field->setDescription('description');
        $this->section->addField($field);

        $field = new Fields\Text('name');
        $field->addValidator(new GroupNameExist())->addValidator(new NotEmptyWithTrim());
        $this->section->addField($field);

        $field = new Fields\SelectGlobalLang('type');
        $field->setAvalibleValues(Groups\Constants::getTranslatedTypes())->notEmpty()->setDescription('type_description');
        $this->section->addField($field);

        $groupid = Request::getValue('groupid');
        $field = new Fields\Select('products');
        $field->setAvalibleValues(Groups\Manage::getProducts($groupid))->notEmpty()->setDescription('products_description')->enableMultiple();
        $this->section->addField($field);

        $field = new Fields\Select('defaultEmailTemplate');
        $field->setAvalibleValues(EmailTemplates::getEmailTemplatesIdAsKeyAndNameAsValue(false))->notEmpty()->setDescription('description');
        $this->section->addField($field);

        $field = new Fields\Text('hours');
        $field->setDescription('description')->notEmpty()->addValidator(new PositiveNumber());
        $this->section->addField($field);

        return $this->section;
    }
}
