<?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\App\Libs\Product\ProductManager;
use ModulesGarden\Servers\OpenXchange\Core\UI\Widget\Forms\Fields\Text;
use ModulesGarden\Servers\OpenXchange\Core\UI\Widget\Forms\Fields\Hidden;
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\Core\UI\Widget\Forms\Fields\InputGroupElements;
use ModulesGarden\Servers\OpenXchange\App\UI\Client\EmailForwarder\Providers\EditForwarderDataProvider;
/**
 *
 * Created by PhpStorm.
 * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
 * Date: 18.09.19
 * Time: 09:29
 * Class EditForwarderForm
 */
class EditForwarderForm extends SortedFieldForm implements ClientArea
{
    use FormExtendedTrait;

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

    public function initContent()
    {
        $this->setFormType(FormConstants::UPDATE);
        $this->setProvider(new EditForwarderDataProvider());
        $this->initFields();
        $this->loadDataToForm();
    }

    public function initFields()
    {
        $field = new Hidden();
        $field->setId('id');
        $field->setName('id');
        $this->addField($field);
        
        $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 Text('forwarder');
        $email->notEmpty();
        $this->addField($email);
    }
}