<?php
namespace ModulesGarden\Servers\OpenXchange\App\UI\Client\EmailAccount\Sections;
use ModulesGarden\Servers\OpenXchange\App\Libs\Product\ProductManager;
use ModulesGarden\Servers\OpenXchange\App\Libs\Zimbra\Components\Api\Soap\Repository\ClassOfServices;
use ModulesGarden\Servers\OpenXchange\App\Traits\FormExtendedTrait;
use ModulesGarden\Servers\OpenXchange\App\UI\Client\Others\Sections\FreeFieldsSection;
use ModulesGarden\Servers\OpenXchange\App\Validators\PasswordsValidator;
use ModulesGarden\Servers\OpenXchange\App\Validators\RepeatPasswordValidator;
use ModulesGarden\Servers\OpenXchange\Core\UI\Widget\Forms\Fields\Hidden;
use ModulesGarden\Servers\OpenXchange\Core\UI\Widget\Forms\Fields\Password;
use ModulesGarden\Servers\OpenXchange\Core\UI\Widget\Forms\Fields\Select;
use ModulesGarden\Servers\OpenXchange\Core\UI\Widget\Forms\Fields\Text;
use ModulesGarden\Servers\OpenXchange\Core\UI\Widget\Forms\Sections\InputGroup;
use ModulesGarden\Servers\OpenXchange\Core\UI\Widget\Forms\Fields\InputGroupElements;

/**
 *
 * Created by PhpStorm.
 * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
 * 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->addField(new Text('display_name'));
        $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);

        $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]);
    }
}
