<?php

namespace ThurData\Servers\KerioEmail\App\UI\Client\DistributionList\Sections;

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

/**
 *
 * Created by PhpStorm.
 * User: ThurData
 * 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->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 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());

    }
}