<?php

/* * ********************************************************************
 * Wordpress_Manager Product developed. (Dec 5, 2017)
 * *
 *
 *  CREATED BY MODULESGARDEN       ->       http://modulesgarden.com
 *  CONTACT                        ->       contact@modulesgarden.com
 *
 *
 * This software is furnished under a license and may be used and copied
 * only  in  accordance  with  the  terms  of such  license and with the
 * inclusion of the above copyright notice.  This software  or any other
 * copies thereof may not be provided or otherwise made available to any
 * other person.  No title to and  ownership of the  software is  hereby
 * transferred.
 *
 *
 * ******************************************************************** */

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

use ModulesGarden\HostingQuotaNotifications\Core\UI\Widget\Forms\BaseForm;
use ModulesGarden\HostingQuotaNotifications\Core\UI\Interfaces\AdminArea;
use \ModulesGarden\HostingQuotaNotifications\App\UI\Groups\Providers\GroupsProvider as GroupsProvider;
use \ModulesGarden\HostingQuotaNotifications\Core\UI\Widget\Forms\AjaxFields\SelectGlobalLang as GlobalLangSelectHQ;
use \ModulesGarden\HostingQuotaNotifications\Core\UI\Widget\Forms\Fields\Text;
use \ModulesGarden\HostingQuotaNotifications\Core\UI\Widget\Forms\Fields;
use \ModulesGarden\HostingQuotaNotifications\Core\Models\Whmcs;
use \ModulesGarden\HostingQuotaNotifications\App\Repositories\GroupsRepository;
use \ModulesGarden\HostingQuotaNotifications\App\UI\Validators;
use \ModulesGarden\HostingQuotaNotifications\App\Libs\Groups;

/**
 * Description of AddGroupPrepareForm
 *
 * @author Artur Pilch <artur.pi@modulesgarden.com>
 */
class AddGroupPrepareForm extends BaseForm implements AdminArea
{
    protected $id = 'addGroupPrepare';

    public function getAllowedActions()
    {
        return ['addGroupPrepare'];
    }

    public function initContent()
    {
        $this->setFormType('addGroupPrepare');
        $this->setProvider(new GroupsProvider());
        $this->initFields();

        $this->loadDataToForm();
    }

    protected function initFields()
    {
        $this->addField((new Text())->initIds('name')->addValidator(new Validators\GroupNameExist())->addValidator(new Validators\NotEmptyWithTrim()));

        $this->addField((new GlobalLangSelectHQ())
                        ->notEmpty()
                        ->initIds('type')
                        ->setAvalibleValues(Groups\Constants::getTranslatedTypes())
                        ->setDescription('type_description'));

        $products = Groups\Manage::getProducts();
        if(empty($products))
        {
            $this->addInternalAllert('noProductsLeft', 'warning');
        }

        $this->addField((new Fields\Select())
                ->notEmpty()
                ->initIds('products')
                ->setAvalibleValues($products)
                ->setDescription('products_description')
                ->enableMultiple());

    }
}
