<?php
/* * ********************************************************************
*  ProxmoxVPS Product developed. (26.03.19)
* *
*
*  CREATED BY MODULESGARDEN       ->       http://modulesgarden.com
*  CONTACT                        ->       contact@modulesgarden.com
*
*
* This software is furnished under a license and may be used and copied
* only  in  accordance  with  the  terms  of such  license and with the
* inclusion of the above copyright notice.  This software  or any other
* copies thereof may not be provided or otherwise made available to any
* other person.  No title to and  ownership of the  software is  hereby
* transferred.
*
*
* ******************************************************************** */


namespace ModulesGarden\Servers\ProxmoxVps\App\UI\Home\Pages;

use ModulesGarden\ProxmoxAddon\App\Services\Vps\ProductService;
use ModulesGarden\ProxmoxAddon\App\Services\Vps\UrlService;
use ModulesGarden\Servers\ProxmoxVps\App\UI\Home\Buttons\RedirectButton;
use ModulesGarden\Servers\ProxmoxVps\Core\Helper\BuildUrl;
use ModulesGarden\Servers\ProxmoxVps\Core\UI\Builder\BaseContainer;
use ModulesGarden\Servers\ProxmoxVps\Core\UI\Interfaces\AdminArea;
use ModulesGarden\Servers\ProxmoxVps\Core\UI\Interfaces\ClientArea;
use function ModulesGarden\Servers\ProxmoxVps\Core\Helper\isAdmin;


class ServiceManagement extends BaseContainer implements ClientArea, AdminArea
{
    use ProductService;
    /**
     * @var UrlService
     */
    private $urlService;

    public function initContent()
    {
        $this->initIds('serviceManagement');
        //Url Service
        $this->urlService = new UrlService();
        //Reinstall
        if (isAdmin() || $this->configuration()->isPermissionReinstall())
        {
            $this->addServiceButton('reinstall');
        }
        //Backups
        if (isAdmin() || $this->configuration()->isPermissionBackup() || $this->configuration()->isPermissionBackupJob())
        {
            $this->addServiceButton('backup');
        }
        //Backup Jobs
        if (isAdmin() || $this->configuration()->isPermissionBackupJob())
        {
            $this->addServiceButton('backupJob');
        }
        //Graphs
        if (isAdmin() || $this->configuration()->isPermissionGraph())
        {
            $this->addServiceButton('graph');
        }
        //Task History
        if (isAdmin() || $this->configuration()->isPermissionTaskHistory())
        {
            $this->addServiceButton('taskHistory');
        }
        //Network
        if (isAdmin() || $this->configuration()->isPermissionNetwork())
        {
            $this->addServiceButton('network');
        }
        //Snapshots
        if (isAdmin() || $this->configuration()->isPermissionSnapshot())
        {
            $this->addServiceButton('snapshot');
        }
        //Firewall
        if (isAdmin() || $this->configuration()->isPermissionFirewall())
        {
            $this->addServiceButton('firewall');
        }
        //Firewall Options
        if (isAdmin() || $this->configuration()->isPermissionFirewallOption())
        {
            $this->addServiceButton('firewallOption');
        }
        //Disks
        if (isAdmin() || $this->configuration()->isPermissionDisk())
        {
            $this->addServiceButton('disk');
        }
    }

    private function addServiceButton($id)
    {
        $rd = new RedirectButton($id);
        $rd->setHref($this->urlService->getUrl($id));
        $rd->setImageUrl(BuildUrl::getAppAssetsURL() . DS . 'img' . DS . 'buttons' . DS . $id . '.png');
        $this->addButton($rd);
    }


}