<?php
/**
 * Menu Controller
 *
 * @author Elze Kool <info@visualmedia.nl>
 */

namespace VisualM\ManagementBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;

/**
 * Menu Controller
 *
 * @author Elze Kool <info@visualmedia.nl>
 */
class MenuController extends Controller
{
    /**
     * Render Menu
     *
     * @return Response Response
     */
    public function renderAction()
    {
        if (null === ($menu_service_name = $this->container->getParameter('visual_m_management_menu_provider'))) {
            return new Response('');
        }

        $menu_provider = $this->container->get($menu_service_name);
        $items = $menu_provider->getItems();
        $request_stack = $this->container->get('request_stack');

        $authChecker = $this->container->get('security.authorization_checker');

        return $this->render('VisualMManagementBundle:Menu:menu.html.twig', [
            'items' => $items,
            'request' => $request_stack->getMasterRequest(),
            'auth_checker' => $authChecker
        ]);

    }

    /**
     * Render Frontend Link
     *
     * @return Response Response
     */
    public function renderAdminAction()
    {
        $frontendLink = null;

        if (null !== ($frontend_route = $this->container->getParameter('visual_m_management_frontend_route'))) {
            $frontendLink = $this->generateUrl($frontend_route, [], true);
        }

        return $this->render('VisualMManagementBundle:Menu:admin.html.twig', [
            'frontend_link' => $frontendLink,
        ]);
    }
}
