<?php
/**
 * @version     $Id$
 * @author      JoomlaUX
 * @package     Joomla.Site
 * @subpackage  mod_jux_easy_megamenu
 * @copyright   Copyright (C) 2008 - 2018 JoomlaUX. All rights reserved.
 * @license     License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Router\Router;

$uri = Uri::getInstance();
$router = Router::getInstance('site');
$vars = $router->parse($uri);
$megamenu = new JoomlaMenu($menuType, $params, $enable_bs3_grid, true, $vars);

list($menu,$options) = $megamenu->render(true);
$menu_nav_class = '';
    $menu_orientation = isset($option['menu_orientation']) ? $option['menu_orientation'] : 'horizontal';
    $menu_nav_class .= ' jux-'.$menu_orientation;
    $menu_float_class = '';
    if($menu_orientation == 'horizontal')
    {   
        if (isset($option['sm_horizontal_drop']))
            $menu_nav_class .= '-'.$option['sm_horizontal_drop'];

        $menu_align = isset($option['menubar_align']) ? $option['menubar_align'] : 'left';
        $menu_nav_align_class = 'jux-align-'.$menu_align;
    } else {
        $menu_nav_align_class = '';
    }

    $sticky_clss = (isset($option['sticky_menu']) && $option['sticky_menu']) == 0 ? 'jux-no-sticky' : '';
    $vertical_rtl = (isset($option['rtl']) && $option['rtl']) == 1 ? ' jux-rtl' : '';

?>
<div id="site-nav-<?php echo $module->id ?>" class="navbar main-navigation clearfix">
  <?php if ($mobileLayout == 1) { ?>
    <button class="collapsible jux-collapse-bar" data-menuicon="<?php echo isset($option['mobile_menu_toggle_icon']) ? $option['mobile_menu_toggle_icon'] : 'icon-menu-3'; ?>" id="jux-collapse-bar-<?php echo $module->id ?>" data-breakpoint="<?php echo isset($option['mobile_breakpoint']) ? $option['mobile_breakpoint'] : 768; ?>">
        <span class="<?php echo isset($option['mobile_menu_toggle_icon']) ? $option['mobile_menu_toggle_icon'] : 'icon-menu-3'; ?> toggle-menu-icn"></span>
        <span class="jux-menu-title"><?php echo isset($option['mobile_menu_title']) ? $option['mobile_menu_title'] : 'MENU'; ?></span>
    </button>
  <?php } ?>
    <div id="jux-easy-megamenu-<?php echo $module->id ?>" class="juxnav <?php echo $mobileLayout == 2 ? 'jux-toggle-without-btn' : ''; ?> <?php echo $menu_nav_align_class . ' ' . $menu_float_class; ?> jux-easy-megamenu-<?php echo $module->id ?> jux-easy-megamenu clearfix<?php echo $menu_nav_class; ?> <?php echo $sticky_clss;  echo $vertical_rtl; ?>">
        <?php
            echo $menu;
        ?>
    </div>
</div>
<!-- add class active in  menu item active -->
<?php
    $input = Factory::getApplication()->input;
    $itemid_currunt = $input->getCmd('Itemid', '');
?>
<script type="text/javascript">
    jQuery(document).ready(function($){
        var itemid = <?php echo $itemid_currunt;?>;
        $('ul.level0 .jux-menu-item-'+itemid).addClass('active');
    });
</script>     
