<?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\Configuration;

use ModulesGarden\HostingQuotaNotifications\App\Libs\TicketStatuses\Manage;
use ModulesGarden\HostingQuotaNotifications\App\UI\Validators\PositiveNumber;
use ModulesGarden\HostingQuotaNotifications\Core\UI\Widget\Forms\BaseForm;
use ModulesGarden\HostingQuotaNotifications\Core\UI\Interfaces\AdminArea;
use \ModulesGarden\HostingQuotaNotifications\Core\UI\Widget\Forms\AjaxFields\SelectGlobalLang;
use \ModulesGarden\HostingQuotaNotifications\Core\UI\Widget\Forms\Fields\Text;
use \ModulesGarden\HostingQuotaNotifications\Core\UI\Widget\Forms\Fields;
use \ModulesGarden\HostingQuotaNotifications\App\Libs\Groups;
use \ModulesGarden\HostingQuotaNotifications\App\Libs\TicketTemplates;
use \ModulesGarden\HostingQuotaNotifications\App\Libs\TicketStatuses;
use \ModulesGarden\HostingQuotaNotifications\App\UI\Groups\Providers\Configuration\StepsProvider;
use \ModulesGarden\HostingQuotaNotifications\App\Helper\Models\EmailTemplates;
use \ModulesGarden\HostingQuotaNotifications\Core\UI\Widget\Forms\Fields\Hidden;
use \ModulesGarden\HostingQuotaNotifications\App\UI\Validators\StepWithThatValue;
use ModulesGarden\HostingQuotaNotifications\App\Helper\Request;
/**
 * Description of AddStepForm
 *
 * @author Artur Pilch <artur.pi@modulesgarden.com>
 */
class AddStepForm extends BaseForm implements AdminArea
{
    protected $id;
    protected $type;
    protected $formType = 'addStep';
    
    public function getAllowedActions()
    {
        return [$this->formType];
    }

    public function initContent()
    {
        
        $this->setFormType($this->formType);
        $this->setProvider(new StepsProvider());

        $this->initBaseFields();

        
        $this->loadDataToForm();
    }
    
    protected function renderFields()
    {

        switch (Groups\Manage::checkType(Request::getValue('groupid')))
        {
            case Groups\Constants::FIXED:
                $this->initFixedFields();
                break;
            case Groups\Constants::TIERED:
                $this->initTieredFields();
                break;
        }
    }

    protected function initBaseFields()
    {
        $this->addField((new Hidden('id')));
     
        $this->addField((new Text('value'))->addValidator(new PositiveNumber())->addValidator(new StepWithThatValue($this)));
        
        $this->addField((new SelectGlobalLang('unit'))->setAvalibleValues(Groups\Constants::UNITS)->setDescription('description'));

        $this->renderFields();

        $this->addField((new Fields\Select('email_template'))->setAvalibleValues(EmailTemplates::getEmailTemplatesIdAsKeyAndNameAsValue(false, true))->setDescription('description'));
        
        $this->addField((new Fields\Select('ticket_template'))->setAvalibleValues(TicketTemplates\Manage::getTicketTemplatesAsKeyIdAndNameAsValue())->setDescription('description'));

        $this->addField((new Fields\Select('ticket_status'))->setAvalibleValues(TicketStatuses\Manage::getAvailableStatuses())->setDescription('description'));

        $this->addField((new SelectGlobalLang('action'))->setAvalibleValues(Groups\Constants::ACTIONS)->setDescription('description'));

    }
    
    protected function initFixedFields()
    {
        $this->addField((new Text())->initIds('countedDays')->addValidator(new PositiveNumber())->setDescription('description'));
    }
    
    protected function initTieredFields()
    {
        
    }
}
