<?php

namespace ThurData\Servers\KerioEmail\App\UI\Client\Setting\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\Fields\Hidden;
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\Fields\Info;
use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\Fields\Switcher;
use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\Sections\InputGroup;
use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\Fields\InputGroupElements;
use ThurData\Servers\KerioEmail\Core\Helper\DnsHelper;

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

    use FormExtendedTrait;

    public function initContent()
    {
        $maildomain = $this->getRequestValue('actionElementId');
        $dns = new DnsHelper();
        $selfdns = $dns->selfDns($maildomain);
        if($selfdns){
            $id = new Hidden();
            $id->setId('id');
            $id->setName('id');
            $editmaildomain = new Hidden();
            $editmaildomain->setId('editmaildomain');
            $editmaildomain->setName('editmaildomain');
            $this->generateDoubleSection([$id, $editmaildomain]);
            $zoneid = new Hidden();
            $zoneid->setId('zoneid');
            $zoneid->setName('zoneid');
            $dnsok = new Hidden();
            $dnsok->setId('dnsok');
            $dnsok->setName('dnsok');
            $this->generateDoubleSection([$zoneid, $dnsok]);
            $editmxthurdata = new Hidden();
            $editmxthurdata->setId('editmxthurdata');
            $editmxthurdata->setName('editmxthurdata');
            $editspfthurdata = new Hidden();
            $editspfthurdata->setId('editspfthurdata');
            $editspfthurdata->setName('editspfthurdata');
            $this->generateDoubleSection([$editmxthurdata, $editspfthurdata]);
            $editdmarcthurdata = new Hidden();
            $editdmarcthurdata->setId('editdmarcthurdata');
            $editdmarcthurdata->setName('editdmarcthurdata');
            $editdkimthurdata = new Hidden();
            $editdkimthurdata->setId('editdkimthurdata');
            $editdkimthurdata->setName('editdkimthurdata');
            $this->generateDoubleSection([$editdmarcthurdata, $editdkimthurdata]);
            $editdkimnamethurdata = new Hidden();
            $editdkimnamethurdata->setId('editdkimnamethurdata');
            $editdkimnamethurdata->setName('editdkimnamethurdata');
            $dkimname = new Hidden();
            $dkimname->setId('dkimname');
            $dkimname->setName('dkimname');
            $this->generateDoubleSection([$editdkimnamethurdata, $dkimname]);

            $infoedit = new Info('infoedit');
            $infoedit->setId('infoedit');
            $infoedit->setName('infoedit');
            $infoedit->setTitle($maildomain);
            $infoedit->setDescription('infoeditmessage');
            $this->addField($infoedit);

            $field = new Text('editmxactive');
            $field->setId('editmxactive');
            $field->setName('editmxactive');
            $this->addField($field);
            $field = new Text('editspf');
            $field->setId('editspf');
            $field->setName('editspf');
            $this->addField($field);
            $field = new Text('editdmarc');
            $field->setId('editdmarc');
            $field->setName('editdmarc');
            $this->addField($field);
            $field = new Text('editdkim');
            $field->setId('editdkim');
            $field->setName('editdkim');
            $this->addField($field);

            $defaults = new Switcher('setDefaults');
            $this->addField($defaults);
        } else {
            $infodns = new Info('infoexternaldns');
            $infodns->setId('infoexternaldns');
            $infodns->setName('infoexternaldns');
            $infodns->setTitle($maildomain);
            $infodns->setDescription('externaldnsmessage');
            $this->addField($infodns);
        }
    }
}