<?php

namespace ModulesGarden\Servers\ProxmoxCloudVps\App\UI\VmCreate\Sections;

use ModulesGarden\ProxmoxAddon\App\Models\VirtualNetwork;
use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\VmCreate\Validators\DiskSizeValidator;
use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\ClientArea;
use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Fields\Select;
use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Fields\Switcher;
use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Fields\Text;
use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Sections\BaseSection;
use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Sections\BoxSection;
use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Sections\HalfPageSection;
use function ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\sl;

class AdditionalDiskSection extends BaseSection implements ClientArea
{
    use ProductService;

    public function initContent()
    {

        $this->initIds('additionalDiskSection');
        $this->initFields();
    }

    public function initFields()
    {
        //size
        $field = new Text('additionalDiskSize');
        $field->addValidator(new DiskSizeValidator('disk',false));
        $field->replaceClasses(['lu-col-md-6']);
        $this->addField($field);
        //bus
        if($this->configuration()->isQemu() && count($this->configuration()->getAdditionalDiskType()) > 1){
            $field = new Select('additionalDiskBus');
            $options=[];
            foreach( $this->configuration()->getAdditionalDiskType() as $entery){
                $options[$entery] = sl("lang")->abtr($entery);
            }
            $field->setAvailableValues($options);
            $field->replaceClasses(['lu-col-md-6']);
            $this->addField($field);
        }
        //format
        if($this->configuration()->isQemu() && count($this->configuration()->getAdditionalDiskFormat()) > 1){
            $field = new Select('additionalDiskFormat');
            $options=[];
            foreach( $this->configuration()->getAdditionalDiskFormat() as $entery){
                $options[$entery] = sl("lang")->abtr($entery);
            }
            $field->setAvailableValues($options);
            $field->replaceClasses(['lu-col-md-6']);
            $this->addField($field);
        }
        if($this->configuration()->isLxc()){
            //mp
            $field = new Text('additionalDiskMp');
            $field->setPlaceholder("/some/path");
            $field->replaceClasses(['lu-col-md-6']);
            $this->addField($field);
        }
        //backup
        if ($this->configuration()->isPermissionAdditionalDiskBackup())
        {
            $field = new Select('additionalDiskBackup');
            $field->setAvailableValues([
                'on' => 'Enable',
                'off'=>'Disable',
            ]);
            $field->replaceClasses(['lu-col-md-6']);
            $this->addField($field);
        }
    }
}