<?php

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

use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
use ModulesGarden\ProxmoxAddon\App\Services\Cloud\UserService;
use ModulesGarden\Servers\ProxmoxCloudVps\App\Helpers\AppParams;
use ModulesGarden\Servers\ProxmoxCloudVps\App\Helpers\ProxmoxAddonValidator;
use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Home\Pages\AccountSummary;
use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Home\Pages\DetailsContainer;
use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Home\Pages\ErrorContainer;
use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\VirtualNetwork\Pages\VirtualNetworkDataTable;
use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\CustomTemplate\Pages\CustomTemplateDataTable;
use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Vms\Pages\VmsDataTable;
use ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper;
use ModulesGarden\Servers\ProxmoxCloudVps\Core\Http\AbstractClientController;
use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Traits\WhmcsParams;

class Home extends AbstractClientController
{

    use WhmcsParams;
    use ProductService;
    use BaseClientController;
    use UserService;

    public function index()
    {
        if ($this->getWhmcsParamByKey('status') != 'Active')
        {
            return;
        }

        if (!ProxmoxAddonValidator::isInstalled())
        {
            ProxmoxAddonValidator::isInstalledOrFail();
        }

        if (!$this->isUser())
        {
            return Helper\view()->addElement(ErrorContainer::class);
        }

        (new AppParams())->initFromWhmcsParams();

        $view = Helper\view();
        $view->addElement((new AccountSummary())->initGraphs())
            ->addElement(VmsDataTable::class);

        if ($this->configuration()->isPermissionVirtualNetwork())
        {
            $view->addElement(VirtualNetworkDataTable::class);
        }
        if ($this->configuration()->isPermissionCustomTemplates())
        {
            $view->addElement(CustomTemplateDataTable::class);
        }
        return $view;
    }


}
