<?php
namespace ThurData\Servers\KerioEmail\App\UI\Client\EmailAccount\Sections;

use ThurData\Servers\KerioEmail\App\Traits\FormExtendedTrait;
use ThurData\Servers\KerioEmail\App\UI\Admin\Custom\Sections\FreeFieldsSection;
use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\Validators\Decimal;
use ThurData\Servers\KerioEmail\App\Validators\PasswordsValidator;
use ThurData\Servers\KerioEmail\App\Validators\RepeatPasswordValidator;
use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\Fields\Password;
use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\Fields\Select;
use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\Fields\Text;
use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\Sections\InputGroup;
use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\Fields\InputGroupElements;

/**
 *
 * Created by PhpStorm.
 * User: ThurData
 * Date: 12.11.19
 * Time: 13:39
 * Class GeneralSection
 */
class GeneralSection extends FreeFieldsSection
{
    protected $id   = 'generalSection';
    protected $name = 'generalSection';

    use FormExtendedTrait;

    public function initContent()
    {
        $this->generateDoubleSection([new Text('firstname'), new Text('lastname')]);

        $email = new InputGroup('usernameGroup');

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

        $this->generateDoubleSection([new Text('display_name'), new Select('status')]);
        $quota = new Text('quota');
        $quota->setDescription('description');
        $quota->addValidator(new Decimal(0));
        $this->generateDoubleSection([$quota, new Select('unit')]);

        $passwd = new Password('password');
        $passwd->setDescription('description');
        $passwd->addValidator(new PasswordsValidator());
        $passwd->notEmpty();

        $repPasswd = (new Password('repeat_password'))->addValidator(new RepeatPasswordValidator());
        $repPasswd->notEmpty();

        $this->generateDoubleSection([$passwd, $repPasswd]);

    }
}