<?php
namespace ModulesGarden\Servers\OpenXchange\App\UI\Client\EmailForwarder\Forms;

use ModulesGarden\Servers\OpenXchange\App\Traits\FormExtendedTrait;
use ModulesGarden\Servers\OpenXchange\Core\UI\Interfaces\ClientArea;
use ModulesGarden\Servers\OpenXchange\Core\UI\Widget\Forms\BaseForm;
use ModulesGarden\Servers\OpenXchange\Core\UI\Widget\Forms\Fields\Text;
use ModulesGarden\Servers\OpenXchange\Core\UI\Widget\Forms\Fields\Textarea;
use ModulesGarden\Servers\OpenXchange\Core\UI\Widget\Forms\Fields\Select;
use ModulesGarden\Servers\OpenXchange\Core\UI\Widget\Forms\FormConstants;
use ModulesGarden\Servers\OpenXchange\Core\UI\Widget\Forms\Sections\InputGroup;
use ModulesGarden\Servers\OpenXchange\App\UI\Client\Others\Forms\SortedFieldForm;
use ModulesGarden\Servers\OpenXchange\App\UI\Client\EmailForwarder\Providers\ForwarderDataProvider;
use ModulesGarden\Servers\OpenXchange\Core\UI\Widget\Forms\Fields\InputGroupElements;

/**
 *
 * Created by PhpStorm.
 * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
 * Date: 10.09.19
 * Time: 13:06
 * Class AddForwarderForm
 */
class AddForwarderForm extends SortedFieldForm implements ClientArea
{
    use FormExtendedTrait;

    protected $id    = 'addForwarderForm';
    protected $name  = 'addForwarderForm';
    protected $title = 'addForwarderForm';

    public function initContent()
    {
        $this->setFormType(FormConstants::CREATE);
        $this->setProvider(new ForwarderDataProvider());
        $this->initFields();
        $this->loadDataToForm();
    }
    public function initFields()
    {
        $email = new InputGroup('usernameGroup');

        $email->addTextField('alias', false, true);
        $email->addInputAddon('emailSign', false, '@');
        $email->addInputComponent((new InputGroupElements\Text('domain'))->addHtmlAttribute('readonly','true'));
        $this->addSection($email);

        $email = new Textarea('forwarder');
        $email->setDescription('forwarderDesc');
        $email->notEmpty();
        $this->addField($email);
    }
}
