<?php

/*--------------------------------------------------------------
# Copyright (C) joomla-monster.com
# License: http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
# Website: http://www.joomla-monster.com
# Support: info@joomla-monster.com
---------------------------------------------------------------*/

defined('_JEXEC') or die;

class JMTemplate extends JMFTemplate {
	public function postSetUp() {

	// ---------------------------------------------------------
	// LESS MAP
	// ---------------------------------------------------------
		
		// --------------------------------------
		// BOOTSTRAP
		// --------------------------------------
		
		$this->lessMap['bootstrap.less'] = array(
			'bootstrap_variables.less', 
            'template_variables.less',  
			'override/ltr/accordion.less',
			'override/ltr/breadcrumbs.less',
			'override/ltr/button-groups.less',
			'override/ltr/buttons.less',
			'override/ltr/dropdowns.less',
			'override/ltr/forms.less',
			'override/ltr/labels-badges.less',
            'override/ltr/navbar.less',
			'override/ltr/navs.less',
			'override/ltr/pager.less',
			'override/ltr/pagination.less',
            'override/ltr/scaffolding.less',
			'override/ltr/tables.less',
            'override/ltr/type.less',
			'override/ltr/utilities.less',
            'override/ltr/wells.less'
        );
        
        $this->lessMap['bootstrap_rtl.less'] = array(
            'bootstrap_variables.less', 
            'template_variables.less',  
			'override/rtl/accordion.less',
			'override/rtl/breadcrumbs.less',
			'override/rtl/button-groups.less',
			'override/rtl/buttons.less',
			'override/rtl/dropdowns.less',
			'override/rtl/forms.less',
			'override/rtl/labels-badges.less',
            'override/rtl/navbar.less',
			'override/rtl/navs.less',
			'override/rtl/pager.less',
			'override/rtl/pagination.less',
            'override/rtl/scaffolding.less',
			'override/rtl/tables.less',
            'override/rtl/type.less',
			'override/rtl/utilities.less',
            'override/rtl/wells.less'
        );
        
        $this->lessMap['bootstrap_responsive.less'] = array(
            'bootstrap_variables.less', 
            'override/ltr/responsive-767px-max.less'
        );
        
        $this->lessMap['bootstrap_responsive_rtl.less'] = array(
            'bootstrap_variables.less', 
            'override/rtl/responsive-767px-max.less'
        );
        
		// --------------------------------------
		// TEMPLATE
		// --------------------------------------
		
        $this->lessMap['template.less'] = array(
            'bootstrap_variables.less', 
            'template_variables.less',
			'override/ltr/buttons.less', 
            'override/ltr/mixins.less', 
            'template_mixins.less',
			//template
			'animated_buttons.less',
			'editor.less',
			'joomla.less',
            'layout.less',
			'menus.less',
            'modules.less',
			//extensions
			'djmediatools.less',
			'djcatalog.less',
			'djtabs.less'
        );
		
		//RTL
		$this->lessMap['template_rtl.less'] = array(
            'bootstrap_variables.less',
            'template_variables.less',
			'override/rtl/buttons.less',
            'override/rtl/mixins.less', 
            'template_mixins.less',
			//extensions
			'djmediatools_rtl.less',
			'djtabs_rtl.less'
        );
		
		//RESPONSIVE
		$this->lessMap['template_responsive.less'] = array(
            'bootstrap_variables.less', 
            'template_variables.less', 
			'override/ltr/buttons.less',
            'override/ltr/mixins.less', 
            'template_mixins.less',
			//extensions
			'djmediatools_responsive.less'
        );
		
		// other files
		// ---------------------------
		
		$common_ltr = array(
			'bootstrap_variables.less',
			'template_variables.less',
			'override/ltr/buttons.less',
			'override/ltr/mixins.less',
			'template_mixins.less'
		);
		
		$common_rtl = array(
			'bootstrap_variables.less',
			'template_variables.less',
			'override/rtl/buttons.less',
			'override/rtl/mixins.less',
			'template_mixins.less'
		);
		
		$this->lessMap['comingsoon.less'] = $common_ltr;
		$this->lessMap['offcanvas.less'] = $common_ltr;
		$this->lessMap['offline.less'] = $common_ltr;
		$this->lessMap['custom.less'] = $common_ltr;
		
		//extensions
		$this->lessMap['djmegamenu.less'] = $common_ltr;
		$this->lessMap['djmegamenu_rtl.less'] = $common_rtl;
		
		$this->lessMap['djcatalog.less'] = $common_ltr;
		$this->lessMap['djcatalog_rtl.less'] = array(
            'bootstrap_variables.less', 
            'template_variables.less', 
			'override/rtl/buttons.less',
            'override/rtl/mixins.less', 
            'template_mixins.less',
			//extensions
			'djcatalog.less'
        );
		
		$this->lessMap['djcatalog_responsive.less'] = $common_ltr;
		
		// ---------------------------------------------------------
		// LESS VARIABLES
		// ---------------------------------------------------------
		
		$bootstrap_vars = array();

		/* Template Layout */

		$templatefluidwidth = $this->params->get('JMfluidGridContainerLg', $this->defaults->get('JMfluidGridContainerLg'));
		$bootstrap_vars['JMfluidGridContainerLg'] = $templatefluidwidth;

		$gutterwidth = $this->params->get('JMbaseSpace', $this->defaults->get('JMbaseSpace'));
		$bootstrap_vars['JMbaseSpace'] = $gutterwidth;

		$offcanvaswidth = $this->params->get('JMoffCanvasWidth', $this->defaults->get('JMoffCanvasWidth'));
		$bootstrap_vars['JMoffCanvasWidth'] = $offcanvaswidth;

		/* Font Modifications */

		//body

		$bodyfontsize = (int)$this->params->get('JMbaseFontSize', $this->defaults->get('JMbaseFontSize'));
		$bootstrap_vars['JMbaseFontSize'] = $bodyfontsize.'px';

		$bodyfonttype = $this->params->get('bodyFontType', $this->defaults->get('bodyFontType'));
		$bodyfontfamily = $this->params->get('bodyFontFamily', $this->defaults->get('bodyFontFamily')); 
		$bodygooglewebfontfamily = $this->params->get('bodyGoogleWebFontFamily', $this->defaults->get('bodyGoogleWebFontFamily')); 
		$bodygeneratedwebfontfamily = $this->params->get('bodyGeneratedWebFont');

		switch($bodyfonttype) {
			case "0" : {
				$bootstrap_vars['JMbaseFontFamily'] = $bodyfontfamily;
				break;
			}
			case "1" :{
				$bootstrap_vars['JMbaseFontFamily'] = $bodygooglewebfontfamily;
				break;
			}
			case "2" :{
				$bootstrap_vars['JMbaseFontFamily'] = $bodygeneratedwebfontfamily;
				break;
			}
			default: {
				$bootstrap_vars['JMbaseFontFamily'] = $this->defaults->get('bodyGoogleWebFontFamily');
				break;
			}
		}

		//module title

	 	$headingsfontsize = (int)$this->params->get('JMmoduleTitleFontSize', $this->defaults->get('JMmoduleTitleFontSize'));
		$bootstrap_vars['JMmoduleTitleFontSize'] = $headingsfontsize.'px';

		$headingsfonttype = $this->params->get('headingsFontType', $this->defaults->get('headingsFontType'));
		$headingsfontfamily = $this->params->get('headingsFontFamily', $this->defaults->get('headingsFontFamily')); 
		$headingsgooglewebfontfamily = $this->params->get('headingsGoogleWebFontFamily', $this->defaults->get('headingsGoogleWebFontFamily'));
		$headingsgeneratedwebfontfamily = $this->params->get('headingsGeneratedWebFont');

		switch($headingsfonttype) {
			case "0" : {
				$bootstrap_vars['JMmoduleTitleFontFamily'] = $headingsfontfamily;
				break;
			}
			case "1" :{
				$bootstrap_vars['JMmoduleTitleFontFamily'] = $headingsgooglewebfontfamily;
				break;
			}
			case "2" :{
				$bootstrap_vars['JMmoduleTitleFontFamily'] = $headingsgeneratedwebfontfamily;
				break;
			}
			default: {
				$bootstrap_vars['JMmoduleTitleFontFamily'] = $this->defaults->get('headingsGoogleWebFontFamily');
				break;
			}
		}

		//top menu horizontal

		$djmenufontsize = (int)$this->params->get('JMtopmenuFontSize', $this->defaults->get('JMtopmenuFontSize'));
		$bootstrap_vars['JMtopmenuFontSize'] = $djmenufontsize.'px';

		$djmenufonttype = $this->params->get('djmenuFontType', $this->defaults->get('djmenuFontType'));
		$djmenufontfamily = $this->params->get('djmenuFontFamily', $this->defaults->get('djmenuFontFamily'));
		$djmenugooglewebfontfamily = $this->params->get('djmenuGoogleWebFontFamily', $this->defaults->get('djmenuGoogleWebFontFamily'));
		$djmenugeneratedwebfontfamily = $this->params->get('djmenuGeneratedWebFont');

			switch($djmenufonttype) {
				case "0" : {
					$bootstrap_vars['JMtopmenuFontFamily'] = $djmenufontfamily;
					break;
				}
				case "1" :{
					$bootstrap_vars['JMtopmenuFontFamily'] = $djmenugooglewebfontfamily;
					break;
				}
				case "2" :{
					$bootstrap_vars['JMtopmenuFontFamily'] = $djmenugeneratedwebfontfamily;
					break;
				}
				default: {
					$bootstrap_vars['JMtopmenuFontFamily'] = $this->defaults->get('djmenuGoogleWebFontFamily');
					break;
				}
			}

		//article title

		$articlesfontsize = (int)$this->params->get('JMarticleTitleFontSize', $this->defaults->get('JMarticleTitleFontSize'));
		$bootstrap_vars['JMarticleTitleFontSize'] = $articlesfontsize.'px';

		$articlesfonttype = $this->params->get('articlesFontType', $this->defaults->get('articlesFontType'));
		$articlesfontfamily = $this->params->get('articlesFontFamily', $this->defaults->get('articlesFontFamily'));
		$articlesgooglewebfontfamily = $this->params->get('articlesGoogleWebFontFamily');
		$articlesgeneratedfontfamily = $this->params->get('articlesGeneratedWebFont');

		switch($articlesfonttype) {
			case "0" : {
				$bootstrap_vars['JMarticleTitleFontFamily'] = $articlesfontfamily;
				break;
			}
			case "1" :{
				$bootstrap_vars['JMarticleTitleFontFamily'] = $articlesgooglewebfontfamily;
				break;
			}
			case "2" :{
				$bootstrap_vars['JMarticleTitleFontFamily'] = $articlesgeneratedfontfamily;
				break;
			}
			default: {
				$bootstrap_vars['JMarticleTitleFontFamily'] = $this->defaults->get('articlesFontFamily');
				break;
			}
		}

		/* Color Modifications */

		//scheme color
		$JMcolorVersion = $this->params->get('JMcolorVersion', $this->defaults->get('JMcolorVersion'));
		$bootstrap_vars['JMcolorVersion'] = $JMcolorVersion;

		//scheme images directory
		$JMimagesDir = $this->params->get('JMimagesDir', 'scheme1');
		$bootstrap_vars['JMimagesDir'] = $JMimagesDir;

		// global
		// -------------------------------------

		$JMpageBackground = $this->params->get('JMpageBackground', $this->defaults->get('JMpageBackground'));
		$bootstrap_vars['JMpageBackground'] = $JMpageBackground;

		$JMbaseFontColor = $this->params->get('JMbaseFontColor', $this->defaults->get('JMbaseFontColor'));
		$bootstrap_vars['JMbaseFontColor'] = $JMbaseFontColor;
		
		$JMmoduleTitleFontColor = $this->params->get('JMmoduleTitleFontColor', $this->defaults->get('JMmoduleTitleFontColor'));
		$bootstrap_vars['JMmoduleTitleFontColor'] = $JMmoduleTitleFontColor;
		
		$JMarticleTitleFontColor = $this->params->get('JMarticleTitleFontColor', $this->defaults->get('JMarticleTitleFontColor'));
		$bootstrap_vars['JMarticleTitleFontColor'] = $JMarticleTitleFontColor;

		$JMborder = $this->params->get('JMborder', $this->defaults->get('JMborder'));
		$bootstrap_vars['JMborder'] = $JMborder;
		
		// topbar
		// -------------------------------------

		$JMtopbarBackground = $this->params->get('JMtopbarBackground', $this->defaults->get('JMtopbarBackground'));
		$bootstrap_vars['JMtopbarBackground'] = $JMtopbarBackground;

		$JMtopbarFontColor = $this->params->get('JMtopbarFontColor', $this->defaults->get('JMtopbarFontColor'));
		$bootstrap_vars['JMtopbarFontColor'] = $JMtopbarFontColor;

		// header
		// -------------------------------------

		$JMheaderFontColor = $this->params->get('JMheaderFontColor', $this->defaults->get('JMheaderFontColor'));
		$bootstrap_vars['JMheaderFontColor'] = $JMheaderFontColor;
		
		$JMheaderTitleColor = $this->params->get('JMheaderTitleColor', $this->defaults->get('JMheaderTitleColor'));
		$bootstrap_vars['JMheaderTitleColor'] = $JMheaderTitleColor;

		$JMheaderBackground = $this->params->get('JMheaderBackground', $this->defaults->get('JMheaderBackground'));
		$bootstrap_vars['JMheaderBackground'] = $JMheaderBackground;
		
		$JMheaderOpacityColor = $this->params->get('JMheaderOpacityColor', $this->defaults->get('JMheaderOpacityColor'));
		$bootstrap_vars['JMheaderOpacityColor'] = $JMheaderOpacityColor;

		$JMheaderOpacity = $this->params->get('JMheaderOpacity', $this->defaults->get('JMheaderOpacity'));
		$bootstrap_vars['JMheaderOpacity'] = $JMheaderOpacity;
	
		// topmenu
		// -------------------------------------

		$JMtopmenuBackground = $this->params->get('JMtopmenuBackground', $this->defaults->get('JMtopmenuBackground'));
		$bootstrap_vars['JMtopmenuBackground'] = $JMtopmenuBackground;

		$JMtopmenuFontColor = $this->params->get('JMtopmenuFontColor', $this->defaults->get('JMtopmenuFontColor'));
		$bootstrap_vars['JMtopmenuFontColor'] = $JMtopmenuFontColor;

		//submenu
		$JMtopSubmenuBackground = $this->params->get('JMtopSubmenuBackground', $this->defaults->get('JMtopSubmenuBackground'));
		$bootstrap_vars['JMtopSubmenuBackground'] = $JMtopSubmenuBackground;

		$JMtopSubmenuFontColor = $this->params->get('JMtopSubmenuFontColor', $this->defaults->get('JMtopSubmenuFontColor'));
		$bootstrap_vars['JMtopSubmenuFontColor'] = $JMtopSubmenuFontColor;

		// top1 and footer-mod
		// -------------------------------------

		$JMtop1Background = $this->params->get('JMtop1Background', $this->defaults->get('JMtop1Background'));
		$bootstrap_vars['JMtop1Background'] = $JMtop1Background;

		$JMtop1FontColor = $this->params->get('JMtop1FontColor', $this->defaults->get('JMtop1FontColor'));
		$bootstrap_vars['JMtop1FontColor'] = $JMtop1FontColor;
		
		$JMtop1TitleColor = $this->params->get('JMtop1TitleColor', $this->defaults->get('JMtop1TitleColor'));
		$bootstrap_vars['JMtop1TitleColor'] = $JMtop1TitleColor;
		
		// colorful line
		// -------------------------------------

		$JMline1Color = $this->params->get('JMline1Color', $this->defaults->get('JMline1Color'));
		$bootstrap_vars['JMline1Color'] = $JMline1Color;

		$JMline2Color = $this->params->get('JMline2Color', $this->defaults->get('JMline2Color'));
		$bootstrap_vars['JMline2Color'] = $JMline2Color;
	
		$JMline3Color = $this->params->get('JMline3Color', $this->defaults->get('JMline3Color'));
		$bootstrap_vars['JMline3Color'] = $JMline3Color;

		$JMline4Color = $this->params->get('JMline4Color', $this->defaults->get('JMline4Color'));
		$bootstrap_vars['JMline4Color'] = $JMline4Color;

		$JMline5Color = $this->params->get('JMline5Color', $this->defaults->get('JMline5Color'));
		$bootstrap_vars['JMline5Color'] = $JMline5Color;
		
		$JMline1Width = $this->params->get('JMline1Width', $this->defaults->get('JMline1Width'));
		$bootstrap_vars['JMline1Width'] = $JMline1Width;
		
		$JMline2Width = $this->params->get('JMline2Width', $this->defaults->get('JMline2Width'));
		$bootstrap_vars['JMline2Width'] = $JMline2Width;

		$JMline3Width = $this->params->get('JMline3Width', $this->defaults->get('JMline3Width'));
		$bootstrap_vars['JMline3Width'] = $JMline3Width;
		
		$JMline4Width = $this->params->get('JMline4Width', $this->defaults->get('JMline4Width'));
		$bootstrap_vars['JMline4Width'] = $JMline4Width;
		
		// bottom
		// -------------------------------------

		$JMbottom1Background = $this->params->get('JMbottom1Background', $this->defaults->get('JMbottom1Background'));
		$bootstrap_vars['JMbottom1Background'] = $JMbottom1Background;

		$JMbottom1FontColor = $this->params->get('JMbottom1FontColor', $this->defaults->get('JMbottom1FontColor'));
		$bootstrap_vars['JMbottom1FontColor'] = $JMbottom1FontColor;

		$JMbottom1TitleColor = $this->params->get('JMbottom1TitleColor', $this->defaults->get('JMbottom1TitleColor'));
		$bootstrap_vars['JMbottom1TitleColor'] = $JMbottom1TitleColor;

		// footer
		// -------------------------------------

		$JMfooterBackground = $this->params->get('JMfooterBackground', $this->defaults->get('JMfooterBackground'));
		$bootstrap_vars['JMfooterBackground'] = $JMfooterBackground;

		$JMfooterFontColor = $this->params->get('JMfooterFontColor', $this->defaults->get('JMfooterFontColor'));
		$bootstrap_vars['JMfooterFontColor'] = $JMfooterFontColor;

		// color ms
		// -------------------------------------

		$JMcolormsModuleBackground = $this->params->get('JMcolormsModuleBackground', $this->defaults->get('JMcolormsModuleBackground'));
		$bootstrap_vars['JMcolormsModuleBackground'] = $JMcolormsModuleBackground;

		$JMcolormsModuleFontColor = $this->params->get('JMcolormsModuleFontColor', $this->defaults->get('JMcolormsModuleFontColor'));
		$bootstrap_vars['JMcolormsModuleFontColor'] = $JMcolormsModuleFontColor;

		$JMcolormsTitleFontColor = $this->params->get('JMcolormsTitleFontColor', $this->defaults->get('JMcolormsTitleFontColor'));
		$bootstrap_vars['JMcolormsTitleFontColor'] = $JMcolormsTitleFontColor;
				
		// offcanvas
		// -------------------------------------

		$JMoffCanvasBackground = $this->params->get('JMoffCanvasBackground', $this->defaults->get('JMoffCanvasBackground'));
		$bootstrap_vars['JMoffCanvasBackground'] = $JMoffCanvasBackground;

		$JMoffCanvasFontColor = $this->params->get('JMoffCanvasFontColor', $this->defaults->get('JMoffCanvasFontColor'));
		$bootstrap_vars['JMoffCanvasFontColor'] = $JMoffCanvasFontColor;

		// -------------------------------------
		// extensions
		// -------------------------------------

		$JMmediatoolsDescriptionFontColor = $this->params->get('JMmediatoolsDescriptionFontColor', $this->defaults->get('JMmediatoolsDescriptionFontColor'));
		$bootstrap_vars['JMmediatoolsDescriptionFontColor'] = $JMmediatoolsDescriptionFontColor;

		$JMmediatoolsDescriptionBackground = $this->params->get('JMmediatoolsDescriptionBackground', $this->defaults->get('JMmediatoolsDescriptionBackground'));
		$bootstrap_vars['JMmediatoolsDescriptionBackground'] = $JMmediatoolsDescriptionBackground;

		$JMmediatoolsDescriptionBackgroundOpacity = $this->params->get('JMmediatoolsDescriptionBackgroundOpacity', $this->defaults->get('JMmediatoolsDescriptionBackgroundOpacity'));
		$bootstrap_vars['JMmediatoolsDescriptionBackgroundOpacity'] = $JMmediatoolsDescriptionBackgroundOpacity;
		
		// -------------------------------------

		$this->params->set('jm_bootstrap_variables', $bootstrap_vars);

		// -------------------------------------
		// compile LESS
		// -------------------------------------

		$app=JFactory::getApplication();

		// Offline Page
		$this->CompileStyleSheet(JPath::clean(JMF_TPL_PATH.'/less/offline.less'), true);

		// DJ-Catalog
		$djcatalog_theme_css = $this->CompileStyleSheet(JPath::clean(JMF_TPL_PATH.'/less/djcatalog.less'), true, true);
		$djcatalog_theme_rtl_css = $this->CompileStyleSheet(JPath::clean(JMF_TPL_PATH.'/less/djcatalog_rtl.less'), true, true);
		$djcatalog_responsive_css = $this->CompileStyleSheet(JPath::clean(JMF_TPL_PATH.'/less/djcatalog_responsive.less'), true, true);

		$djcatalog_theme_less = 'templates/'.$app->getTemplate().'/less/djcatalog.less';
		$djcatalog_theme_rtl_less = 'templates/'.$app->getTemplate().'/less/djcatalog_rtl.less';
		$djcatalog_responsive_less = 'templates/'.$app->getTemplate().'/less/djcatalog_responsive.less';
		
		// DJ-Megamenu
		$djmegamenu_theme_css = $this->CompileStyleSheet(JPath::clean(JMF_TPL_PATH.'/less/djmegamenu.less'), true, true);
		$djmegamenu_theme_css_rtl = $this->CompileStyleSheet(JPath::clean(JMF_TPL_PATH.'/less/djmegamenu_rtl.less'), true, true);

		$djmegamenu_theme_less = 'templates/'.$app->getTemplate().'/less/djmegamenu.less';
		$djmegamenu_theme_less_rtl = 'templates/'.$app->getTemplate().'/less/djmegamenu_rtl.less';
		
		// -------------------------------------
		// extensions themes
		// -------------------------------------

		$themer=(int)$this->params->get('themermode',0)==1?true:false;

		if($themer) {// add LESS files when Theme Customizer enabled
			$urlsToRemove=array(
			'templates/'.$app->getTemplate().'/css/djmegamenu.css' => array('url' => $djmegamenu_theme_less, 'type' => 'less'),
			'templates/'.$app->getTemplate().'/css/djmegamenu_rtl.css' => array('url' => $djmegamenu_theme_less_rtl, 'type' => 'less'),
			'components/com_djcatalog2/themes/'.$app->getTemplate().'/css/theme.css' => array('url' => $djcatalog_theme_less, 'type' => 'less'),
			'components/com_djcatalog2/themes/'.$app->getTemplate().'/css/responsive.css' => array('url' => $djcatalog_responsive_less, 'type' => 'less'),
			'components/com_djcatalog2/themes/'.$app->getTemplate().'/css/theme.rtl.css' => array('url' => $djcatalog_theme_rtl_less, 'type' => 'less'),
			'components/com_djcatalog2/themes/'.$app->getTemplate().'/css/responsive.rtl.css' => array('url' => $djcatalog_responsive_less, 'type' => 'less')
			);
			$app->set('jm_remove_stylesheets',$urlsToRemove);

		} else {// add CSS files when Theme Customizer disabled
			$urlsToRemove=array(
			'templates/'.$app->getTemplate().'/css/djmegamenu.css' => array('url' => $djmegamenu_theme_css, 'type' => 'css'),
			'templates/'.$app->getTemplate().'/css/djmegamenu_rtl.css' => array('url' => $djmegamenu_theme_css_rtl, 'type' => 'css'),
			'components/com_djcatalog2/themes/'.$app->getTemplate().'/css/theme.css' => array('url' => $djcatalog_theme_css, 'type' => 'css'),
			'components/com_djcatalog2/themes/'.$app->getTemplate().'/css/responsive.css' => array('url' => $djcatalog_responsive_css, 'type' => 'css'),
			'components/com_djcatalog2/themes/'.$app->getTemplate().'/css/theme.rtl.css' => array('url' => $djcatalog_theme_rtl_css, 'type' => 'css'),
			'components/com_djcatalog2/themes/'.$app->getTemplate().'/css/responsive.rtl.css' => array('url' => $djcatalog_responsive_css, 'type' => 'css')
			);
			$app->set('jm_remove_stylesheets',$urlsToRemove);
		}
	}
}