<?php
/**
 * Flex @package Helix Framework
 * Template Name - Flex
 * @author Aplikko http://www.aplikko.com
 * @copyright Copyright (c) 2025 Aplikko
 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
*/
//no direct accees
defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Version;

$doc = Factory::getDocument();
$app = Factory::getApplication();
$menu = $app->getMenu()->getActive();

//Load Helix
$helix3_path = JPATH_PLUGINS . '/system/helix3/core/helix3.php';

if (file_exists($helix3_path))
{
	require_once($helix3_path);
	// Deprecated: $this->helix3 = helix3::getInstance();
	$helix3 = helix3::getInstance();
}
else
{
	die('Please install and activate helix plugin');
}

// Remove the generator meta tag
if($this->params->get('remove_joomla_generator')) {
  $this->setGenerator(null);
}

//Coming Soon
if ($helix3->getParam('comingsoon_mode'))
{
	header("Location: " . Route::_(Uri::root(true) . "/index.php?tmpl=comingsoon", false));
	exit();
}

//Class Classes
$body_classes = '';
if ($helix3->getParam('sticky_header'))
{
	$body_classes .= ' sticky-header';
}

$body_classes .= ($helix3->getParam('boxed_layout', 0)) ? ' layout-boxed' : ' layout-fluid';

if (isset($menu) && $menu)
{
	if ($menu->getParams()->get('pageclass_sfx'))
	{
		$body_classes .= ' ' . $menu->getParams()->get('pageclass_sfx');
	}
}

$body_classes .= ' off-canvas-menu-init';

//Body Background Image
if ($bg_image = $helix3->getParam('body_bg_image'))
{
	$body_style = 'background-image: url(' . Uri::base(true) . '/' . $bg_image . ');';
	$body_style .= 'background-repeat: ' . $helix3->getParam('body_bg_repeat') . ';';
	$body_style .= 'background-size: ' . $helix3->getParam('body_bg_size') . ';';
	$body_style .= 'background-attachment: ' . $helix3->getParam('body_bg_attachment') . ';';
	$body_style .= 'background-position: ' . $helix3->getParam('body_bg_position') . ';';
	$body_style = 'body.site {' . $body_style . '}';
	
	$doc->addStyledeclaration($body_style);
} else {
	$body_style = 'body.site {background-color:'.$helix3->PresetParam('_bg').';}';
	$doc->addStyledeclaration($body_style);
}

//Boxed Layout Width (Flex) 
if ($this->params->get('boxed_layout') == 1) { 
	$boxed_background_color = '';
	
	$boxed_sticky_header = '
	.layout-boxed .sticky,
	.layout-boxed .sticky .sticky__wrapper,
	.layout-boxed .sticky .sticky__wrapper .sp-megamenu-parent .sp-dropdown{
		max-width:'.$helix3->getParam('boxed_layout_width').'px;
		margin:0 auto;
	}';

	if ($this->params->get('boxed_background_color') != '') { 
		$boxed_background_color = 'background-color:'.$helix3->getParam('boxed_background_color').';box-shadow:0 0 7px rgba(0,0,0,0.2);';
	} 
	$body_innerwrapper_overflow = '';
	
	if ($helix3->getParam('boxed_layout_spacing') != 0) { 
		$boxed_layout_spacing = 'margin:' . $helix3->getParam('boxed_layout_spacing') . 'px auto;';
		$boxed_layout_spacing .= $boxed_background_color;
		$boxed_layout_spacing .= 'max-width:'.$helix3->getParam('boxed_layout_width').'px;';
		$boxed_layout_spacing = 'body.layout-boxed .body-wrapper {margin:-' . $helix3->getParam('boxed_layout_spacing') . 'px auto 0;padding:' . $helix3->getParam('boxed_layout_spacing') . 'px 0 0;}body.layout-boxed .body-innerwrapper {' . $boxed_layout_spacing . '}
		';
		$doc->addStyledeclaration($boxed_layout_spacing);
	} else {
		$boxed_layout_spacing = $boxed_background_color;
		$boxed_layout_spacing .= 'max-width:'.$helix3->getParam('boxed_layout_width').'px;';
		$boxed_layout_spacing = 'body.layout-boxed .body-innerwrapper {' . $boxed_layout_spacing . '}
		';
		$doc->addStyledeclaration($boxed_layout_spacing);
	}
} else { 
	$body_innerwrapper_overflow = ' body_innerwrapper_overflow';
	$boxed_sticky_header = '';
}

// SmoothScroll.js (Flex)
if ($this->params->get('smooth_scroll_version') == '0') { 
	//Disabled
	$smooth_scroll_js = '';
} else if ($this->params->get('smooth_scroll_version') == '2') { 
	$smooth_scroll_js = ',SmoothScroll-1.4.10.js';
	} else if ($this->params->get('smooth_scroll_version') == '3') { 
	$smooth_scroll_js = ',SmoothScroll-1.5.1.js';
} else {
	$smooth_scroll_js = ',SmoothScroll.js';
}

// Variables JS (Flex)
$js_vars = '
var sp_preloader = "' . $this->params->get('preloader') . '";
var sp_offanimation = "' . $this->params->get('offcanvas_animation') . '";
var stickyHeaderVar = "' . $this->params->get('sticky_header') . '";

';

// Sticky Header appear point (Flex)
if ($this->params->get('sticky_header') == 1) {
	$stickyHeaderAppearVar = ($helix3->getParam('sticky_header_appear_point')) ? 'var stickyHeaderAppearPoint = ' . $this->params->get('sticky_header_appear_point') . ';' : 'var stickyHeaderAppearPoint = 250;';
} else {
	$stickyHeaderAppearVar = '';
}

$all_js_vars = $js_vars . $stickyHeaderAppearVar;
$all_js_vars = preg_replace(array('/([\s])\1+/', '/[\n\t]+/m'), '', $all_js_vars); // Remove whitespace
$doc->addScriptdeclaration($all_js_vars);

//Custom CSS
if ($custom_css = $helix3->getParam('custom_css'))
{
	$doc->addStyledeclaration($custom_css);
}

//Custom JS
if ($custom_js = $helix3->getParam('custom_js'))
{
	$doc->addScriptdeclaration($custom_js);
}

// Removing unwanted FontAwesome file (loaded by default in Joomla 5)
if (JVERSION > 4) {
	$this->getWebAssetManager()->registerStyle('fontawesome', '');
	//$this->getWebAssetManager()->registerStyle('awesomplete', '');
}
?>
<!DOCTYPE html>
<html lang="<?php echo $this->language; ?>" dir="<?php echo $this->direction; ?>">
	<head>
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<?php $helix3->loadHead(); ?>
		<?php
			$megabgcolor = ($helix3->PresetParam('_megabg')) ? $helix3->PresetParam('_megabg') : '#ffffff';
			$megabgtx = ($helix3->PresetParam('_megatx')) ? $helix3->PresetParam('_megatx') : '#333333';

			$preloader_bg = ($helix3->getParam('preloader_bg')) ? $helix3->getParam('preloader_bg') : '#f5f5f5';
			$preloader_tx = ($helix3->getParam('preloader_tx')) ? $helix3->getParam('preloader_tx') : '#4a4a4a';
		
			// load css, less and js (Flex)
			// $helix3->addCSS('bootstrap.min.css'); // CSS Files old way
			// Add the latest Bootstrap version via cdn
			$helix3->addCSS('https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css'); // CSS Files from CDN

			// Add FontAwesome icons 7.1.0
			$helix3->addCSS('fontawesome.min.css, fa-v4-shims.css');
	
		
			// load css, less and js (Flex)
			$helix3->addJS('https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.bundle.min.js, jquery.easing.min.js, main.js'.$smooth_scroll_js) // JS Files
			->lessInit()->setLessVariables(array(
				'preset' => $helix3->Preset(),
				'bg_color' => $helix3->PresetParam('_bg'),
				'text_color' => $helix3->PresetParam('_text'),
				'major_color' => $helix3->PresetParam('_major'),
				'preloader_bg' => $preloader_bg,
				'preloader_tx' => $preloader_tx,
			))
			->addLess('master', 'template');
		
			//$helix3->addJS($smooth_scroll_js);
		
				
			//RTL
			if ($this->direction == 'rtl')
			{
				$helix3->addCSS('bootstrap-rtl.min.css')
					->addLess('rtl', 'rtl');
			}
			
			$helix3->addLess('presets', 'presets/' . $helix3->Preset(), array('class' => 'preset'));
			
			//Before Head
			if ($before_head = $helix3->getParam('before_head')) {
				echo $before_head . "\n";
			}
		?>
	</head>
	
	<body class="<?php echo $helix3->bodyClass($body_classes); ?>">
		<?php // added class "body-wrapper". It was only "off-canvas-menu-wrap" before.(Flex) ?>
        <div class="body-wrapper off-canvas-menu-wrap">
            <div class="body-innerwrapper<?php echo $body_innerwrapper_overflow; ?>">
				<?php $helix3->generatelayout(); ?>
			</div>
		</div>
		
		<!-- Off Canvas Menu -->
		<div class="offcanvas-menu">
			<a href="#" class="close-offcanvas" aria-label="Close"><i class="fas fa-times" aria-hidden="true" title="<?php echo Text::_('HELIX_CLOSE_MENU'); ?>"></i></a>
			<div class="offcanvas-inner">
				<?php if ($helix3->countModules('offcanvas')) : ?>
					<jdoc:include type="modules" name="offcanvas" style="sp_xhtml" />
				<?php else : ?>
					<p class="alert alert-warning">
						<?php echo Text::_('HELIX_NO_MODULE_OFFCANVAS'); ?>
					</p>
				<?php endif; ?>
			</div>
		</div>
		<?php
		// Header (Flex)
		$header_height = ($helix3->getParam('header_height')) ? $helix3->getParam('header_height') : '90';
		
		//$header_height = ($helix3->getParam('header_height')) ? $helix3->getParam('header_height') : '90';
		
		$sticky_header_height = ($helix3->getParam('sticky_header_height')) ? $helix3->getParam('sticky_header_height') : '75';
		$header_link_color = ($helix3->getParam('header_link_color')) ? 'color:'. $helix3->getParam('header_link_color') : '';
		$header_active_link_color = ($helix3->getParam('header_active_link_color')) ? $helix3->getParam('header_active_link_color') : '';
		$headerbgcolor = ($helix3->getParam('headerbg')) ? 'background:'. $helix3->getParam('headerbg') .';' : '';
		$stickybgcolor = ($helix3->getParam('stickybg')) ? 'background:'. $helix3->getParam('stickybg') .';' : '';
		$mega_dropdown_bg = ($helix3->getParam('mega_dropdown_bg')) ? 'background:'. $helix3->getParam('mega_dropdown_bg') : '';
		$mega_dropdown_color = ($helix3->getParam('mega_dropdown_color')) ? 'color:'. $helix3->getParam('mega_dropdown_color') : '';
		$sticky_appearance_animation = ($helix3->getParam('sticky_appearance_animation')) ? '-webkit-animation-name:'. $helix3->getParam('sticky_appearance_animation') .';animation-name:'. $helix3->getParam('sticky_appearance_animation') .';' : '-webkit-animation-name:fade-in-down;animation-name:fade-in-down;';
		$sticky_appearance_none = ($helix3->getParam('sticky_appearance_animation') == 'none') ? '-webkit-transition:none;-moz-transition:none;-o-transition:none;transition:none;' : '';
		
		$sticky_header_link_color = ($helix3->getParam('sticky_header_link_color')) ? 'color:'. $helix3->getParam('sticky_header_link_color') : '';
		$sticky_header_active_link_color = ($helix3->getParam('sticky_header_active_link_color')) ? $helix3->getParam('sticky_header_active_link_color') : '';
		
		// Off-canvas
		$offcanvas_bg = ($helix3->getParam('offcanvas_bg')) ? 'background:'. $helix3->getParam('offcanvas_bg') : '';
		$offcanvas_color = ($helix3->getParam('offcanvas_color')) ? $helix3->getParam('offcanvas_color') : '';
		$offcanvas = '.offcanvas-menu{'. $offcanvas_bg .'}.offcanvas-menu ul li a{color: '. $offcanvas_color .'}.offcanvas-menu .offcanvas-inner .search input.inputbox{border-color: '. $offcanvas_color .'}';
		$doc->addStyledeclaration($offcanvas);
		
		$header_styling = '
		#sp-header .top-search-wrapper .icon-top-wrapper,
		#sp-header .top-search-wrapper .icon-top-wrapper >i:before,
		.sp-megamenu-wrapper > .sp-megamenu-parent >li >a,
		.sp-megamenu-wrapper #offcanvas-toggler,
		.sp-megamenu-wrapper #offcanvas-toggler .js-menu-toggle,
		#sp-header .modal-login-wrapper span,
		#sp-header .ap-my-account i.pe-7s-user,
		#sp-header .ap-my-account .info-text,
		#sp-header .mod-languages,
		#sp-header .logo,
		#cart-menu,
		#cd-menu-trigger,
		.cd-cart,
		.cd-cart > i{  
			height:' . $header_height . 'px;
			line-height:' . $header_height . 'px;
		}
		.total_products{top:calc('. $header_height .'px / 2 - 22px);}
		
		.sp-megamenu-wrapper #offcanvas-toggler .js-menu-toggle span.lines {margin-top: calc('. $header_height .'px / 2 - 17px);}
		
		#sp-header,
		.transparent-wrapper{
			height:' . $header_height . 'px;
			'.$headerbgcolor.'
		}
		.transparent,
		.sticky-top{
			'.$headerbgcolor.'
		}
		#sp-header #sp-menu .sp-megamenu-parent >li >a,
		#sp-header #sp-menu .sp-megamenu-parent li .sp-dropdown >li >a,
		#sp-header .top-search-wrapper .icon-top-wrapper i,
		#sp-header #cd-menu-trigger i,
		#sp-header .cd-cart i,
		#sp-header .top-search-wrapper{'. $header_link_color .'}
		#sp-header #sp-menu .sp-dropdown .sp-dropdown-inner{'. $mega_dropdown_bg .'}
		#sp-header #sp-menu .sp-dropdown .sp-dropdown-inner li.sp-menu-item >a,
		#sp-header #sp-menu .sp-dropdown .sp-dropdown-inner li.sp-menu-item.separator >a,
		#sp-header #sp-menu .sp-dropdown .sp-dropdown-inner li.sp-menu-item.separator >a:hover,
		#sp-header .sp-module-content ul li a,
		#sp-header .vm-menu .vm-title{'. $mega_dropdown_color .'}		
		';
		// Onepage
		if ($helix3->getParam('header_active_link_color') != '') { 
			$active_link_color = '
			#sp-header #sp-menu .sp-megamenu-parent >li.active a,
			#sp-header #sp-menu .sp-megamenu-parent >li.current-item >a,
            #sp-header #sp-menu .sp-megamenu-parent >li.current-item.active>a,
			#sp-header #sp-menu .sp-megamenu-parent >li.sp-has-child.active >a,	
			#offcanvas-toggler >i,
			#offcanvas-toggler >i:hover{color:'. $header_active_link_color .'}
			#sp-header #sp-menu .sp-megamenu-parent .sp-dropdown li.sp-menu-item.current-item>a,
			#sp-header #sp-menu .sp-megamenu-parent .sp-dropdown li.sp-menu-item.current-item.active>a,
			#sp-header #sp-menu .sp-megamenu-parent .sp-dropdown li.sp-menu-item.current-item.active:hover>a,
			#sp-header #sp-menu .sp-megamenu-parent .sp-dropdown li.sp-menu-item a:hover{
			  color: #fff;
			  background-color:'. $header_active_link_color .';
			}
			#sp-header.onepage .sp-megamenu-parent li.active a,
			#sp-header.onepage .sp-megamenu-parent li.active:first-child >a.page-scroll{
				color:'. $header_active_link_color .';
				border-bottom-color:'. $header_active_link_color .';
			}
			';
		} else {
			$active_link_color = '';
		}
		
		if ($this->params->get('sticky_header') == 1) { 
			$sticky_header_styling = '
			.sticky .logo,
			.sticky #cart-menu,
			.sticky #cd-menu-trigger,
			.sticky .cd-cart,
			.sticky .cd-cart >i,
			.sticky .menu-is-open >i,
			#sp-header.sticky .modal-login-wrapper span,
			#sp-header.sticky .ap-my-account i.pe-7s-user,
			#sp-header.sticky .ap-my-account .info-text,
			#sp-header.sticky .mod-languages,
			#sp-header.sticky .top-search-wrapper .icon-top-wrapper,
			#sp-header.sticky .top-search-wrapper .icon-top-wrapper >i:before,
			.sticky .sp-megamenu-wrapper > .sp-megamenu-parent >li >a,
			.sticky .sp-megamenu-wrapper #offcanvas-toggler,
			.sticky .sp-megamenu-wrapper #offcanvas-toggler .js-menu-toggle,
			.sticky #sp-logo a.logo{ 
				height:'.$sticky_header_height.'px;
				line-height:'.$sticky_header_height.'px;
			 }
			 
		
			 
			 .sticky .sp-megamenu-wrapper #offcanvas-toggler .js-menu-toggle span.lines {margin-top: calc('. $sticky_header_height .'px / 2 - 17px);}
			 
			 .sticky .total_products{top: calc('. $sticky_header_height .'px / 2 - 22px);}
			 
			 .sticky .sticky__wrapper{
				'.$stickybgcolor.'
				 height:'.$sticky_header_height.'px;
				 '. $sticky_appearance_none . $sticky_appearance_animation .'
			}
			'. $boxed_sticky_header .'
			.sticky .sticky__wrapper .sp-sticky-logo {
				height:'.$sticky_header_height.'px;
			}
			.sticky.onepage .sticky__wrapper,
			.sticky.white .sticky__wrapper,
			.sticky.transparent .sticky__wrapper{
				'.$stickybgcolor.'
			} 
			#sp-header.sticky #sp-menu .sp-megamenu-wrapper .sp-megamenu-parent >li >a,
			#sp-header.sticky .top-search-wrapper,
			#sp-header.sticky .top-search-wrapper .icon-top-wrapper i,
			#sp-header.sticky #cd-menu-trigger i,
			#sp-header.sticky .cd-cart i{
				'. $sticky_header_link_color .';
			}	
			#sp-header.sticky #sp-menu .sp-megamenu-wrapper .sp-megamenu-parent >li.active>a,
			#sp-header.sticky #sp-menu .sp-megamenu-wrapper .sp-megamenu-parent >li.current-item>a,
			#sp-header.sticky #sp-menu .sp-megamenu-wrapper .sp-megamenu-parent >li.sp-has-child.active>a,
			.sticky #offcanvas-toggler >i,
			.sticky #offcanvas-toggler >i:hover{
				color:'. $sticky_header_active_link_color .';
			}
			 ';
			 
			$header_css = $header_styling . $active_link_color . $sticky_header_styling;
			$header_css = preg_replace(array('/([\s])\1+/', '/[\n\t]+/m'), '', $header_css); // Remove whitespace
			$doc->addStyledeclaration($header_css);
		} else { 
			$header_css = $header_styling . $active_link_color;
			$header_css = preg_replace(array('/([\s])\1+/', '/[\n\t]+/m'), '', $header_css); // Remove whitespace
			$doc->addStyledeclaration($header_css);
		}
		
			if ($this->params->get('compress_css'))
			{
				$helix3->compressCSS();
			}
			
			$tempOption = $app->input->get('option');
			
			if ($this->params->get('compress_js') && $tempOption != 'com_config')
			{
				$helix3->compressJS($this->params->get('exclude_js'));
			}
			
			//before body
			if ($before_body = $helix3->getParam('before_body'))
			{
				echo $before_body . "\n";
			}
		
			// Removes: jQuery(window).on('load', function() {new JCaption('img.caption');});
			if (isset($this->_script['text/javascript'])) {
				$this->_script['text/javascript'] = preg_replace('%jQuery\(\window\)\.on\(\'load\',\s*function\(\)\s*{\s*new\s*JCaption\(\'img.caption\'\);\s*}\);\s*%', '', $this->_script['text/javascript']);
				if (empty($this->_script['text/javascript']))
					unset($this->_script['text/javascript']);
			}

			// Removes Mootools library	
			if($this->params->get('remove_mootools')) {
				unset($doc->_scripts[$this->baseurl . '/media/system/js/mootools-core.js']);
				unset($doc->_scripts[$this->baseurl . '/media/system/js/core.js']);
				unset($doc->_scripts[$this->baseurl . '/media/system/js/mootools-more.js']);
				unset($doc->_scripts[$this->baseurl . '/media/system/js/caption.js']);
			}
		?>
				
		<jdoc:include type="modules" name="debug" />
		<jdoc:include type="modules" name="helixpreloader" />
				
		<!-- Go to top -->
		<?php if ($this->params->get('goto_top')) : ?>
			<a href="javascript:void(0)" class="scrollup" aria-label="<?php echo Text::_('HELIX_GOTO_TOP'); ?>">&nbsp;</a>
		<?php endif; ?>
	</body>
</html>