<?php

namespace ModulesGarden\Servers\ZimbraEmail\App\UI\Client\DistributionList\Sections;


use ModulesGarden\Servers\ZimbraEmail\App\UI\Admin\Custom\Fields\ExtendedSelect;
use ModulesGarden\Servers\ZimbraEmail\App\UI\Admin\Custom\Sections\FreeFieldsSection;
use ModulesGarden\Servers\ZimbraEmail\App\Validators\EmailValidator;
use ModulesGarden\Servers\ZimbraEmail\App\Validators\TaggerEmailValidator;
use function ModulesGarden\Servers\ZimbraEmail\Core\Helper\di;
use ModulesGarden\Servers\ZimbraEmail\Core\UI\Widget\Forms\Fields\Hidden;
use ModulesGarden\Servers\ZimbraEmail\Core\UI\Widget\Forms\Fields\InputGroupElements\Text as InputText;
use ModulesGarden\Servers\ZimbraEmail\Core\UI\Widget\Forms\Fields\Select;
use ModulesGarden\Servers\ZimbraEmail\Core\UI\Widget\Forms\Fields\Tagger;
use ModulesGarden\Servers\ZimbraEmail\Core\UI\Widget\Forms\Fields\Text;
use ModulesGarden\Servers\ZimbraEmail\Core\UI\Widget\Forms\Fields\Textarea;
use ModulesGarden\Servers\ZimbraEmail\Core\UI\Widget\Forms\Sections\InputGroup;

/**
 *
 * Created by PhpStorm.
 * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
 * Date: 02.10.19
 * Time: 09:38
 * Class EditMembersDistribution
 */
class EditMembersDistribution extends FreeFieldsSection
{
    protected $id   = 'editMembersDistribution';
    protected $name = 'editMembersDistribution';

    public function initContent()
    {
        $email = new InputGroup('usernameGroup');

        //$email->addTextField('listmail', false, true);
        $email->addInputComponent((new InputText('listmail'))->addHtmlAttribute('readonly','true'));
        $email->addInputAddon('emailSign', false, '@');
        $email->addInputComponent((new InputText('domain'))->addHtmlAttribute('readonly','true'));
        $this->addSection($email);

        $this->addField((new Text('displayName')));

        $this->addField(new Textarea('description'));

        $this->addField((new Select('memberList'))->enableMultiple());

        $this->addField((new Tagger('customMember'))->setPlaceholder(di('lang')->absoluteT('mail@example.com'))->addValidator(new TaggerEmailValidator()));
        ;

        /**
         * id for edit form
         */
        $this->addField((new Hidden('id')));

        /**
         * current email list for edit form
         */
        $this->addField((new ExtendedSelect('emailAliasesActually'))->enableMultiple()->enableHidden());

        /**
         * current member list for edit form
         */
        $this->addField((new ExtendedSelect('memberListActually'))->enableMultiple()->enableHidden());

        /**
         * current owners list for edit form
         */
        $this->addField((new ExtendedSelect('ownersActually'))->enableMultiple()->enableHidden());

    }
}