<?php

namespace ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Vm\Pages;

use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Backup\Pages\BackupDataTable;
use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Disk\Pages\DiskDataTable;
use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\MountPoint\Pages\MountPointDataTable;
use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Network\Pages\NetworkLxcDataTable;
use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Network\Pages\NetworkQemuDataTable;
use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Reinstall\Pages\GraphsTab;
use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Reinstall\Pages\IsoDataTable;
use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Reinstall\Pages\ReinstallTab;
use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Reinstall\Pages\TemplateDataTable;
use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Snapshot\Pages\SnapshotDataTable;
use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\TaskHistory\Pages\TaskHistoryDataTable;
use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\VirtualInterface\Pages\VirtualInterfaceDataTable;
use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\ClientArea;
use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\TabsWidget\TabsWidget;
use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Network\Pages\NetworkTab;

class VmTabs extends TabsWidget implements ClientArea
{
    use ProductService;

    public function initContent()
    {
        $this->addElement(new DetailTab);
        if(!$this->configuration()->isDetailsCombinedView()){
            //disk
            if ($this->configuration()->isQemu() && $this->configuration()->isPermissionDisk())
            {
                $this->addElement(new DiskDataTable());
            }
            //mount point
            if ($this->configuration()->isLxc() && $this->configuration()->isPermissionDisk())
            {
                $this->addElement(new MountPointDataTable());
            }
            //network
            if (($this->configuration()->isQemu() && $this->configuration()->isPermissionNetwork()) || ($this->configuration()->isLxc() && $this->configuration()->isPermissionNetwork()))
            {
                $this->addElement(new NetworkTab());
            }
        }
        //snapshot
        if ($this->configuration()->isPermissionSnapshot())
        {
            $this->addElement(new SnapshotDataTable());
        }
        //backup
        if ($this->configuration()->isPermissionBackupJob())
        {
            $this->addElement(new BackupTab());
        }
        elseif ($this->configuration()->isPermissionBackup())
        {
            $this->addElement(new BackupDataTable());
        }
        if ($this->configuration()->isPermissionFirewallOption() && $this->configuration()->isPermissionFirewall())
        {
            $this->addElement(new FirewallTab());
        }
        //task history
        if ($this->configuration()->isPermissionTaskHistory())
        {
            $this->addElement(new TaskHistoryDataTable());
        }
        /**
         * Graphs
         */
        if($this->configuration()->isPermissionGraph()){
            $this->addElement(new GraphsTab());
        }
        /**
         * Reinstall
         */
        if ($this->configuration()->isQemu() && $this->configuration()->isPermissionOsTemplate() && $this->configuration()->isPermissionIsoImage())
        {
            $this->addElement(ReinstallTab::class);
        }
        elseif ($this->configuration()->isQemu() && $this->configuration()->isPermissionOsTemplate())
        {
            $this->addElement(TemplateDataTable::class);
        }
        elseif ($this->configuration()->isQemu() && $this->configuration()->isPermissionIsoImage())
        {
            $this->addElement(IsoDataTable::class);
            //lxc
        }
        elseif ($this->configuration()->isLxc())
        {
            $this->addElement(TemplateDataTable::class);
        }
    }
}