<?php

$hookManager->register(
    function (\WHMCS\View\Menu\Item $primarySidebar)
    {

        /**
         * @var  \ModulesGarden\Servers\ZimbraEmail\Core\Http\Request $request
         */
        $request = \ModulesGarden\Servers\ZimbraEmail\Core\Helper\sl('request');

        /**
         * return if user is not logged
         */
        if(!$request->getSession('uid'))
        {
            return;
        }

        /**
         * return if service id doesn't exists
         */
        if (!$request->get('id'))
        {
            return;
        }

        /**
         *
         */
        $clientAreaSideBar = new \ModulesGarden\Servers\ZimbraEmail\App\Services\ClientAreaSidebarService($request->get("id"), $primarySidebar);
        if (!$clientAreaSideBar->isActive() || !$clientAreaSideBar->isSupportedModule())
        {
            return;
        }
        if (!function_exists('ModuleBuildParams'))
        {
            require_once \ModulesGarden\Servers\ZimbraEmail\Core\ModuleConstants::getFullPathWhmcs('includes') . DIRECTORY_SEPARATOR . "modulefunctions.php";
        }
        $params = \ModuleBuildParams($request->get("id"));
        \ModulesGarden\Servers\ZimbraEmail\Core\Helper\sl("whmcsParams")->setParams($params);

        //Page Cancel
        if ($request->get('action') == "cancel")
        {
            $clientAreaSideBar->informationReplaceUri();
        } //Page Productdetails
        else
        {
            if ($request->get('action') == "productdetails")
            {
                $clientAreaSideBar->informationReplaceUri();
                $clientAreaSideBar->build();
            }
        }
    }, 943
);
