<?php

namespace ModulesGarden\Servers\ProxmoxVps\App\UI\Admin\Product\Sections\Qemu;

use ModulesGarden\Servers\ProxmoxVps\Core\UI\Interfaces\AdminArea;
use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\BaseField;
use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\Switcher;
use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\Text;
use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\Textarea;
use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Sections\BoxSection;
use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Sections\HalfPageSection;

class GuestAgentSection extends BoxSection implements AdminArea
{
    protected $id = 'guestAgentSection';
    protected $name = 'guestAgentSection';
    protected $title = 'guestAgentSection';
    private $sectionFields=[];
    /**
     * @var HalfPageSection
     */
    private $leftSection;
    /**
     * @var HalfPageSection
     */
    private $rightSection;

    public function initContent()
    {
        $this->leftSection = new HalfPageSection('leftSection');
        $this->rightSection = new HalfPageSection('rightSection');
        $this->addSection($this->leftSection)
            ->addSection($this->rightSection);
        $this->initFields();
        $this->addFieldsToSections();
    }

    private function initFields()
    {
        //Guest Agent [on/off]
        $field = new Switcher('customconfigoption[agent]');
        $field->setDescription('tip');
        $this->addSectionField($field);
        //Template User
        $field = new Switcher('customconfigoption[agentTemplateUser]');
        $field->setDescription('tip');
        $this->addSectionField($field);
        //Service Password
        $field = new Switcher('customconfigoption[agentServicePassword]');
        $field->setDescription('tip');
        $this->addSectionField($field);
        //Configure Network
        $field = new Switcher('customconfigoption[agentConfigureNetwork]');
        $field->setDescription('tip');
        $this->addSectionField($field);
    }

    public function addSectionField(BaseField $field)
    {
        $this->sectionFields[] = $field;
        return $this;
    }

    private function addFieldsToSections(){
        foreach($this->sectionFields as $k => $field){
            if($k % 2 == 0 ){
                $this->leftSection->addField($field);
            }else{
                $this->rightSection->addField($field);
            }
        }
        unset($this->sectionFields);
    }

}
