<?php

namespace ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Admin\Product\Sections;

use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\AdminArea;
use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Fields\Switcher;
use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Sections\BoxSection;
use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Sections\HalfPageSection;

class FirewallOptionSection extends BoxSection implements AdminArea
{
//    protected $id = 'clientNotificationSection';
//    protected $name = 'clientNotificationSection';
//    protected $title = 'clientNotificationSection';
    /**
     * @var HalfPageSection
     */
    private $leftSection;
    /**
     * @var HalfPageSection
     */
    private $rightSection;

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

    private function initFields()
    {
        //enable
        $field = new Switcher("customconfigoption[firewalOptionEnable]");
        $this->addField($field);
        //dhcp
        $field = new Switcher("customconfigoption[firewalOptionDhcp]");
        $field->setDefaultValue("on");
        $this->addField($field);
        //ndp
        $field = new Switcher("customconfigoption[firewalOptionNdp]");
        $field->setDefaultValue("on");
        $this->addField($field);
        //radv
        $field = new Switcher("customconfigoption[firewalOptionRadv]");
        $this->addField($field);
        //macfilter
        $field = new Switcher("customconfigoption[firewalOptionMacfilter]");
        $field->setDefaultValue("on");
        $this->addField($field);
        //ipfilter
        $field = new Switcher("customconfigoption[firewalOptionIpfilter]");
        $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;
    }

}
