<?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', 
            'template_mixins.less',
			//template
			'animated_buttons.less',
			'editor.less',
			'joomla.less',
            'layout.less',
			'menus.less',
            'modules.less',
			//extensions
			'djimageslider.less'
        );
		
		//RTL
		$this->lessMap['template_rtl.less'] = array(
            'bootstrap_variables.less',
            'template_variables.less',
			'override/rtl/buttons.less',
            'template_mixins.less',
			//extensions
			'djimageslider_rtl.less'
        );
		
		//RESPONSIVE
		$this->lessMap['template_responsive.less'] = array(
            'bootstrap_variables.less', 
            'template_variables.less', 
			'override/ltr/buttons.less',
            'template_mixins.less',
			//extensions
			'djimageslider_responsive.less'
        );
		
		//EXTENDED LAYOUTS
		$this->lessMap['extended_layouts.less'] = array(
            'bootstrap_variables.less',
            'template_variables.less',
			'override/rtl/buttons.less',
            'template_mixins.less',
			//
			'high_contrast1.less',
			'high_contrast2.less',
			'high_contrast3.less',
			'night_version.less'
        );
		
		// other files
		// ---------------------------
		
		$common_ltr = array(
			'bootstrap_variables.less',
			'template_variables.less',
			'override/ltr/buttons.less',
			'template_mixins.less'
		);
		
		$common_rtl = array(
			'bootstrap_variables.less',
			'template_variables.less',
			'override/rtl/buttons.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;
		
		$this->lessMap['high_contrast.less'] = $common_ltr;
		
		$this->lessMap['font_switcher.less'] = $common_ltr;
		
		//extensions
		$this->lessMap['djmegamenu.less'] = $common_ltr;
		$this->lessMap['djmegamenu_rtl.less'] = $common_rtl;
		
		// ---------------------------------------------------------
		// 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;
			}
		}

		//blog title

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

		$blogfonttype = $this->params->get('blogFontType', $this->defaults->get('blogFontType'));
		$blogfontfamily = $this->params->get('blogFontFamily', $this->defaults->get('blogFontFamily'));
		$bloggooglewebfontfamily = $this->params->get('blogGoogleWebFontFamily');
		$bloggeneratedfontfamily = $this->params->get('blogGeneratedWebFont');

		switch($blogfonttype) {
			case "0" : {
				$bootstrap_vars['JMblogTitleFontFamily'] = $blogfontfamily;
				break;
			}
			case "1" :{
				$bootstrap_vars['JMblogTitleFontFamily'] = $bloggooglewebfontfamily;
				break;
			}
			case "2" :{
				$bootstrap_vars['JMblogTitleFontFamily'] = $bloggeneratedfontfamily;
				break;
			}
			default: {
				$bootstrap_vars['JMblogTitleFontFamily'] = $this->defaults->get('blogFontFamily');
				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;

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

		//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;

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

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

		$JMheadingFontColor = $this->params->get('JMheadingFontColor', $this->defaults->get('JMheadingFontColor'));
		$bootstrap_vars['JMheadingFontColor'] = $JMheadingFontColor;
		
		// 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;

		// topmenu / logo-nav
		// -------------------------------------

		$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;
		
		// header & top2 & bottom3
		// -------------------------------------

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

		// top3 & bottom1 & footer
		// -------------------------------------

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

		$JMtop3FontColor = $this->params->get('JMtop3FontColor', $this->defaults->get('JMtop3FontColor'));
		$bootstrap_vars['JMtop3FontColor'] = $JMtop3FontColor;
		
		$JMtop3ModuleTitle = $this->params->get('JMtop3ModuleTitle', $this->defaults->get('JMtop3ModuleTitle'));
		$bootstrap_vars['JMtop3ModuleTitle'] = $JMtop3ModuleTitle;
		
		// 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
		// -------------------------------------

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

		// -------------------------------------

		$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-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')
			);
			$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')
			);
			$app->set('jm_remove_stylesheets',$urlsToRemove);
		}
	}
}