<?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
 */

use Joomla\CMS\Factory;
use Joomla\CMS\Helper\ModuleHelper;
use Joomla\CMS\Language\LanguageHelper;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Uri\Uri;

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

require_once dirname(__FILE__) . '/helper.php';
require_once dirname(__FILE__).'/includes/menu/menu.php';

$document = Factory::getDocument();
$document->addStyleSheet(Uri::base().'modules/mod_jux_easy_megamenu/assets/font-awesome/css/font-awesome.css');
$document->addStyleSheet(Uri::base().'modules/mod_jux_easy_megamenu/assets/css/default.css');
$customcss = 'modules/mod_jux_easy_megamenu/assets/css/style/custom-'.$module->id.'.css';

$moduleID = $module->id;
$theme		= $params->get('theme', 'default');

$menuType = $params->get('mod_menu', 'mainmenu');


$menu_options = (array) json_decode($params->get('mega_options',''),true);
if(isset($menu_options[$params['mod_menu']])) {
    $option = $menu_options[$params['mod_menu']];
} else {
    $option = array();
}

//mobile layout
$mobileLayout = isset($option['mobile_layout']) ? $option['mobile_layout'] : 1;

$tm_font_family = isset($option['topmenu_font_family']) ? $option['topmenu_font_family'] : 'inherit';
$tm_font_url = isset($option['topmenu_font_url']) ? $option['topmenu_font_url'] : '';
$submenu_font_family = isset($option['submenu_font_family']) ? $option['submenu_font_family'] : 'inherit';
$submenu_font_url = isset($option['submenu_font_url']) ? $option['submenu_font_url'] : '';
if($tm_font_family !== 'inherit') {
    $google_font_link1 = 'https://fonts.googleapis.com/css?' . $tm_font_url;
    $document->addStyleSheet($google_font_link1);
}
if($submenu_font_family !== 'inherit') {
    $google_font_link2 = 'https://fonts.googleapis.com/css?' . $submenu_font_url;
    $document->addStyleSheet($google_font_link2);
}

HTMLHelper::_('jquery.framework');
$document->addScript('modules/mod_jux_easy_megamenu/assets/js/menu.js');

$enable_bs3_grid =  $params->get('bootstrap_grid', 0);
if($enable_bs3_grid == 1) {
    $document->addStyleSheet(JUri::base(true).'/modules/mod_jux_easy_megamenu/assets/bootstrap/css/bootstrap.css');
    $document->addScript(Uri::base(true).'/modules/mod_jux_easy_megamenu/assets/bootstrap/js/bootstrap.min.js');
}

$meta = LanguageHelper::getMetadata(Factory::getLanguage()->getTag());
$rtl = $meta['rtl'] == 0 ? false : true;

if($rtl) {
    $document->addScriptDeclaration('
    jQuery(document).ready(function(){
        if(!jQuery("body").hasClass("rtl")) { jQuery("body").addClass("rtl"); }
    });');
  $document->addStyleSheet(Uri::base().'modules/mod_jux_easy_megamenu/assets/css/jux-rtl.css');
}

$enable_sticky = (isset($option['sticky_menu']) && $option['sticky_menu']) == 0 ? false : true;

if ($enable_sticky) {
    $document->addScript('modules/mod_jux_easy_megamenu/assets/js/stickymenu.js');
}

if (ModJUXEasyMegaMenuHelper::getCssProcessor($params,$customcss, $moduleID)){
    $document->addStyleSheet(Uri::base().$customcss);
}
require (ModuleHelper::getLayoutPath('mod_jux_easy_megamenu'));
