<?php
/**
  * Ahead WebSoft Technologies Pvt Ltd.
  * @copyright  Copyright 2006-2026 Ahead WebSoft Technologies Pvt Ltd.
  * @license    https://www.socialengine.com/policies
*/
?>
 <?php if(in_array('mainMenu',$this->options)){ ?> 
<div class="header_left_panel">
<ul class="navigation mobile_menu">
        <?php foreach( $this->navigation as $link ): ?>
          <?php 
            $explodedString = explode(' ', $link->class);
            $menuName = end($explodedString); 
            $moduleName = str_replace('core_main_', '', $menuName);
            if(strpos($moduleName, 'custom_') !== 0){
              $moduleName = $moduleName.'_main';
            }
           ?>
            <?php $subMenus = Engine_Api::_()->getApi('menus', 'core')->getNavigation($moduleName); 
            $menuSubArray = $subMenus->toArray();
            ?>
  					<li class="<?php echo $link->get('active') ? 'active' : '' ?>"  >
  						<a href='<?php echo $link->getHref() ?>' class="<?php echo $link->getClass() ? ' ' . $link->getClass() : ''  ?>"
  								<?php if( $link->get('target') ): ?> target='<?php echo $link->get('target') ?>' <?php endif; ?>  data-bs-toggle="tooltip" data-bs-placement="right" title="<?php echo $this->translate($link->getlabel()) ?>">
  						<i class="<?php echo $link->get('icon') ? $link->get('icon') : 'fa fa-star' ?>"></i>
  						<span><?php echo $this->translate($link->getlabel()) ?></span>
  						<?php if(engine_count($menuSubArray) > 0 && $this->submenu): ?>
  						<i class="fa fa-angle-down open_submenu"></i>
  						<?php endif; ?>
  						</a>
  						<?php if(engine_count($menuSubArray) > 0 && $this->submenu): ?>
  						<ul class="main_menu_submenu" style="display:none;">
                <?php 
                  $counter = 0; 
                  foreach( $subMenus as $subMenu): 
                  $active = isset($menuSubArray[$counter]['active']) ? $menuSubArray[$counter]['active'] : 0;
                  ?>
  								<li class="clearfix <?php echo ($active) ? 'selected_sub_main_menu' : '' ?>">
  									<a href="<?php echo $subMenu->getHref(); ?>" <?php if( $subMenu->get('target') ): ?> target='<?php echo $subMenu->get('target') ?>' <?php endif; ?> class="<?php echo $subMenu->getClass(); ?>">
  									<i class="<?php echo $subMenu->get('icon') ? $subMenu->get('icon') : 'fa fa-star' ?>"></i><span><?php echo $this->translate($subMenu->getLabel()); ?></span>
  									</a>
  								</li>
  								<?php 
                  $counter++;
                  endforeach; ?>
  						</ul>
  						<?php endif; ?>
  					</li>
  			  <?php endforeach; ?>
  			</ul>
				<div class="cross_button">
        <i class="fas fa-times"></i>
      </div>
    
  	</div>
		<?php } ?>	


<script type="text/javascript">
	// Main Menu Toggle
	en4.core.runonce.add(function() {
		scriptJquery(".inspira_main_menu  .toggle_button").click(function () {
			if(scriptJquery(".inspira_main_menu .inspira_main_menu_container").hasClass('header-nav-open')){
				scriptJquery(".inspira_main_menu .inspira_main_menu_container").removeClass('header-nav-open')
			}
			else{
				scriptJquery(".inspira_main_menu .inspira_main_menu_container").addClass('header-nav-open');
			}
		});
	});
	
	scriptJquery(document).click(function(event) {
		if (!scriptJquery(event.target).closest(".inspira_main_menu .inspira_main_menu_container , .inspira_main_menu .toggle_button").length) {
		scriptJquery("html").find(".inspira_main_menu .inspira_main_menu_container,.cross_button ").removeClass("header-nav-open");
		scriptJquery("html").find("body").removeClass("header-open");
		}
	});
	en4.core.runonce.add(function() {
		scriptJquery(".inspira_main_menu .toggle_button").click(function () {
			if(scriptJquery("body ").hasClass('header-open')){
			scriptJquery("body").removeClass('header-open')
			}else{
			scriptJquery("body").addClass('header-open');
			}
		});
	});
	en4.core.runonce.add(function() {
		scriptJquery(".header_left_panel .cross_button ").click(function(){
			scriptJquery(".header_left_panel").removeClass("header-nav-open");
		});
	});

 // Main Menu Toggle
 en4.core.runonce.add(function() {
      scriptJquery(".inspira_header  .toggle_button  ").click(function () {
        if(scriptJquery(".inspira_header .header_left_panel").hasClass('header-nav-open')){
          scriptJquery(".inspira_header .header_left_panel").removeClass('header-nav-open')
        }
        else{
          scriptJquery(".inspira_header .header_left_panel").addClass('header-nav-open');
        }
      });
    });

    scriptJquery(document).click(function(event) {
      if (!scriptJquery(event.target).closest(".inspira_header .header_left_panel,.inspira_header .toggle_button ").length) {
        scriptJquery("html").find(".inspira_header .header_left_panel").removeClass("header-nav-open");
        scriptJquery("html").find("body").removeClass("header-open");
      }
    });
    en4.core.runonce.add(function() {
      scriptJquery(".inspira_header .toggle_button").click(function () {
        if(scriptJquery("body ").hasClass('header-open')){
          scriptJquery("body ").removeClass('header-open')
        }else{
          scriptJquery("body  ").addClass('header-open');
        }
      });
    });

   // Sub Menu
   AttachEventListerSE('click','.open_submenu',function(e){
     if(scriptJquery(this).parent().parent().find('ul').children().length == 0)
       return true;
     e.preventDefault();
     if(scriptJquery(this).parent().hasClass('has_submenu')){
       scriptJquery('.has_submenu').parent().find('ul').slideToggle('slow');
       scriptJquery(this).parent().removeClass('has_submenu');
     } else {
       scriptJquery('.has_submenu').parent().find('ul').slideToggle('slow');
       scriptJquery(this).parent().parent().find('ul').slideToggle('slow');
       scriptJquery('.has_submenu').removeClass('has_submenu');
       scriptJquery(this).parent().addClass('has_submenu');
     }
     return false;
   });
</script>
