<?php


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


use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\AccountSummary\Providers\AccountSummaryProvider;
use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Validators\HostnameValidator;
use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\VmCreate\Fields\OsTemplateSelect;
use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Fields\Text;
use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Fields\Textarea;
use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Sections\RawSection;
use function ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\sl;

class TopSection extends RawSection {
    use ProductService;

    public function initContent() {
        //name
        $field = new Text('name');
        $field->addValidator(new HostnameValidator());
        $this->addField($field);
        //osTemplate
        if($this->configuration()->isPermissionOsTemplate() || $this->configuration()->isLxc()){
            $field =new OsTemplateSelect('osTemplate');
            $field->notEmpty();
            $this->addField( $field);
        }
        //description
        $field = new Textarea('description');
        //$field->unsetShowTitle();
        //$field->setPlaceholder(sl('lang')->tr('Description'));
        $field->setRows(2);
        $field->replaceClasses(['lu-m-t-1x lu-m-b-0x']);
        $this->addField($field);

        $provider = new AccountSummaryProvider();
        $this->customTplVars['bars'] = $provider->read();
    }
}