<?php

namespace ModulesGarden\Servers\ProxmoxVps\App\Http\Client;

use ModulesGarden\ProxmoxAddon\App\Services\Vps\ProductService;
use ModulesGarden\Servers\ProxmoxVps\App\Helpers\AppParams;
use ModulesGarden\Servers\ProxmoxVps\App\UI\Reinstall\Pages\IsoDataTable;
use ModulesGarden\Servers\ProxmoxVps\App\UI\Reinstall\Pages\ReinstallTab;
use ModulesGarden\Servers\ProxmoxVps\App\UI\Reinstall\Pages\TemplateDataTable;
use ModulesGarden\Servers\ProxmoxVps\Core\Helper;
use ModulesGarden\Servers\ProxmoxVps\Core\Http\AbstractClientController;
use ModulesGarden\Servers\ProxmoxVps\Core\UI\Traits\WhmcsParams;

class Reinstall extends AbstractClientController
{
    use WhmcsParams;
    use ProductService;
    use BaseClientController;

    public function index()
    {
        (new AppParams())->initFromWhmcsParams();
        $this->acl()->reinstall();
        Helper\sl("sidebar")->getSidebar("managementProxmoxVps")->getChild("reinstall")->setActive(true);
        if (!$this->isVpsCreated())
        {
            return $this->onVpsBuild();
        }
        else if ($this->configuration()->isQemu() && $this->configuration()->isPermissionOsTemplate() && $this->configuration()->isPermissionIsoImage())
        {
            return Helper\view()->addElement(ReinstallTab::class);
        }
        else
        {
            if ($this->configuration()->isQemu() && $this->configuration()->isPermissionOsTemplate())
            {
                return Helper\view()->addElement(TemplateDataTable::class);
            }
            else
            {
                if ($this->configuration()->isQemu() && $this->configuration()->isPermissionIsoImage())
                {
                    return Helper\view()->addElement(IsoDataTable::class);
                    //lxc
                }
                else
                {
                    if ($this->configuration()->isLxc())
                    {
                        return Helper\view()->addElement(TemplateDataTable::class);
                    }
                }
            }
        }


    }

}
