<?php

namespace ModulesGarden\ProxmoxAddon\App\Helper;

use ModulesGarden\ProxmoxAddon\App\UI\DoeSectionsSettings\Providers\DoeSettingsDataProvider;
use ModulesGarden\ProxmoxAddon\Core\Helper;
use ModulesGarden\ProxmoxAddon\Core\Http\Request;

/**
 * Description of ClientAreaPage
 *
 * @author Rafał Ossowski <rafal.os@modulesgarden.com>
 */
class ClientAreaPage
{
    /**
     * @var Request
     */
    protected $request;

    /**
     * @var DoeSettingsDataProvider
     */
    protected $doeSettingsDataProvider;
    protected $vars = [];

    /**
     * @param Request $request
     * @param DoeSettingsDataProvider $doeSettingsDataProvider
     */
    public function __construct(Request $request, DoeSettingsDataProvider $doeSettingsDataProvider)
    {
        $this->request                 = $request;
        $this->doeSettingsDataProvider = $doeSettingsDataProvider;
    }

    public function setVars(array $vars = [])
    {
        $this->vars = $vars;

        return $this;
    }

    public function isOrderdomain()
    {
        return (($this->getVar("currentPageName") === "orderdomain") ? true : false);
    }

    protected function getVar($key = "")
    {
        if (isset($this->vars[$key]) === false)
        {
            return null;
        }

        return $this->vars[$key];
    }

    public function isChangePage()
    {
        $fileName                 = $this->getVar("filename");
        $action                   = $this->getRequest()->get('a', false);
        $domeain                  = $this->getRequest()->get('domain', false);
        $replaceStandardRegistrar = $this->doeSettingsDataProvider->getValueById("replaceStandardRegistrar");

        if ($fileName == 'domainchecker' || ($fileName == 'cart' && $action == 'add' && $domeain == 'transfer') || ($fileName == 'cart' && $action == 'add' && $domeain == 'register')
        )
        {
            if ($replaceStandardRegistrar === "on")
            {
                return true;
            }
        }

        return false;
    }

    /**
     * @return Request
     */
    public function getRequest()
    {
        return $this->request;
    }

    public function redirect($action = "", array $params = [])
    {
        return Helper\redirect("orderDomain", $action, $params);
    }
}
