<?php
namespace ModulesGarden\Servers\ZimbraEmail\App\UI\Admin\ProductConfiguration\Forms;
use ModulesGarden\Servers\ZimbraEmail\App\UI\Admin\Custom\Forms\BaseFormExtended;
use ModulesGarden\Servers\ZimbraEmail\App\UI\Admin\ProductConfiguration\Providers\ConfigurableOptionManager;
use function ModulesGarden\Servers\ZimbraEmail\Core\Helper\di;
use ModulesGarden\Servers\ZimbraEmail\Core\UI\Interfaces\AdminArea;
use ModulesGarden\Servers\ZimbraEmail\Core\UI\Widget\Forms\BaseForm;
use ModulesGarden\Servers\ZimbraEmail\Core\UI\Widget\Forms\Fields\Switcher;
use ModulesGarden\Servers\ZimbraEmail\Core\UI\Widget\Forms\FormConstants;

/**
 * Class CreateConfigurableAction
 * User: Nessandro
 * Date: 2019-09-29
 * Time: 15:31
 */

class CreateConfigurableAction extends BaseFormExtended implements AdminArea
{
    protected $id    = 'createConfigurableAction';
    protected $name  = 'createConfigurableAction';
    protected $title = 'createConfigurableAction';

    public function initContent()
    {
        $lang = di('lang');
        $lang->addReplacementConstant('configurableOptionsNameUrl', '<a style="    color: #31708f; text-decoration: underline;" href="https://docs.whmcs.com/Addons_and_Configurable_Options" target="blank">here</a>');
        $this->addInternalAlert($lang->absoluteT('configurableOptionsWhmcsInfo'), 'info', null, true);


        $this->setFormType(FormConstants::CREATE);
        $this->setProvider(new ConfigurableOptionManager());
        $this->loadDataToForm();
        $dataProvider = $this->getFormData();
        if (is_array($dataProvider['fields']))
        {
            foreach ($dataProvider['fields'] as $key => $name)
            {
                $this->addField((new Switcher($key))->setDefaultValue('on')->setRawTitle($key.'|'.$name));
            }
        }
        $this->loadDataToForm();
    }
}