<?php


namespace ModulesGarden\ProxmoxAddon\App\UI\Settings\Sections;


use ModulesGarden\ProxmoxAddon\App\UI\Validators\IpAddressAndHostnameValidator;
use ModulesGarden\ProxmoxAddon\Core\UI\Widget\Forms\Fields\Switcher;
use ModulesGarden\ProxmoxAddon\Core\UI\Widget\Forms\Fields\Text;
use ModulesGarden\ProxmoxAddon\Core\UI\Widget\Forms\Sections\BoxSection;
use ModulesGarden\ProxmoxAddon\Core\UI\Widget\Forms\Sections\HalfPageSection;


class AdminAreaSection extends BoxSection
{

    protected $id = 'adminAreaSection';
    protected $name = 'adminAreaSection';
    protected $title = 'adminAreaSection';

    protected $leftSection;
    protected $rightSection;

    public function initContent(){
        //Add Sections
        $this->leftSection = new HalfPageSection('left');
        $this->rightSection = new HalfPageSection('right');
        $this->addSection($this->leftSection);
        $this->addSection($this->rightSection);
        $this->initFields();
    }

    protected function initFields(){
        //Start
        $field = new Switcher('permissionStart');
        $field->setDescription('tip');
        $field->setDefaultValue("on");
        $this->addField($field);
        //Reboot
        $field = new Switcher('permissionReboot');
        $field->setDescription('tip');
        $field->setDefaultValue("on");
        $this->addField($field);
        //Stop
        $field = new Switcher('permissionStop');
        $field->setDescription('tip');
        $field->setDefaultValue("on");
        $this->addField($field);
        //Shutdown
        $field = new Switcher('permissionShutdown');
        $field->setDescription('tip');
        $field->setDefaultValue("on");
        $this->addField($field);
        //noVNC Console
        $field = new Switcher('permissionNovnc');
        $field->setDescription('tip');
        $field->setDefaultValue("on");
        $this->addField($field);
        //SPICE Console
        $field = new Switcher('permissionSpice');
        $field->setDescription('tip');
        $field->setDefaultValue("on");
        $this->addField($field);
        //xterm.js Console
        $field = new Switcher('permissionXtermjs');
        $field->setDescription('tip');
        $this->addField($field);
        //Migrate
        $field = new Switcher('permissionMigrate');
        $field->setDescription('tip');
        $field->setDefaultValue("on");
        $this->addField($field);
        //Information
        $field = new Switcher('permissionInformation');
        $field->setDescription('tip');
        $field->setDefaultValue("on");
        $this->addField($field);
        //IpAddresses
        $field = new Switcher('permissionIpAddresses');
        $field->setDescription('tip');
        $field->setDefaultValue("on");
        $this->addField($field);
        //IPSet
        $field = new Switcher('permissionIpSet');
        $field->setDescription('tip');
        $field->setDefaultValue("on");
        $this->addField($field);
        //Reinstallation
        $field = new Switcher('permissionReinstall');
        $field->setDescription('tip');
        $field->setDefaultValue("on");
        $this->addField($field);
        //MRTG Graphics
        $field = new Switcher('permissionGraph');
        $field->setDescription('tip');
        $field->setDefaultValue("on");
        $this->addField($field);
        //User Details
        $field = new Switcher('permissionUserDetails');
        $field->setDescription('tip');
        $field->setDefaultValue("on");
        $this->addField($field);
        //AccountResources
        $field = new Switcher('permissionAccountResources');
        $field->setDescription('tip');
        $field->setDefaultValue("on");
        $this->addField($field);
        //Vms
        $field = new Switcher('permissionVms');
        $field->setDescription('tip');
        $field->setDefaultValue("on");
        $this->addField($field);
    }

    public function addField($field){
        $total = count($this->leftSection->getFields()) + count($this->rightSection->getFields());
        if($total % 2 == 0){
            $this->leftSection->addField($field);
        }else{
            $this->rightSection->addField($field);
        }
        return $this;
    }

}
