<?php
/**
  * Ahead WebSoft Technologies Pvt Ltd.
  * @copyright  Copyright 2006-2026 Ahead WebSoft Technologies Pvt Ltd.
  * @license    https://www.socialengine.com/policies
*/
?>
<div class="mobile_navigation">
   <a href="javascript:void(0)" class="mobile_menu">
      <i class="fas fa-bars"></i>
   </a>
   <a href="javascript:void(0)" class="mobile_menu mobile_menu_close">
      <i class="fas fa-times"></i>
   </a>
  <ul class="mobile_navigation_menu navigation">
    <?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; ?> >
            <i class="<?php echo $link->get('icon') ? $link->get('icon') : 'fa fa-star' ?>"></i>
          <span><?php echo $this->translate($link->getlabel()) ?></span>
          <?php if(count($menuSubArray) > 0): ?>
            <i class="fa fa-angle-down"></i>
          <?php endif; ?>
        </a>
        <?php if (engine_count($subMenus) > 0 && $this->submenu): ?>
          <ul class="main_menu_submenu">
            <?php
            $counter = 0;
            foreach ($subMenus as $subMenu):
              $active = isset($menuSubArray[$counter]['active']) ? $menuSubArray[$counter]['active'] : 0;
            ?>
              <li class="harmony_clearfix <?php echo ($active) ? 'selected_sub_main_menu' : '' ?>">
                <a <?php if ($subMenu->get('target')): ?> target='<?php echo $subMenu->get('target') ?>' <?php endif; ?> href="<?php echo $subMenu->getHref(); ?>" class="<?php echo $subMenu->getClass(); ?>">
                  <?php if ($this->show_menu_icon): ?><i class="fa fa-angle-right"></i><?php endif; ?><span><?php echo $this->translate($subMenu->getLabel()); ?></span>
                </a>
              </li>
            <?php
              $counter++;
            endforeach; ?>
          </ul>
        <?php endif; ?>   
      </li>
    <?php endforeach; ?>
  </ul>
</div>  

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

<script>
  en4.core.runonce.add(function () {
    scriptJquery(".mobile_navigation_menu > li > a > .fa.fa-angle-down").on("click", function(e){
      e.preventDefault();
      e.stopPropagation();
      var parentLi = scriptJquery(this).closest("li");
      var parentA  = parentLi.children("a");
      var submenu  = parentLi.children(".main_menu_submenu");
      if(submenu.length){
        if(submenu.is(":visible")){
          submenu.slideUp(300);
          parentA.removeClass("open_toggle_menu");
        } 
        else {
          scriptJquery(".main_menu_submenu").slideUp(300);
          scriptJquery(".mobile_navigation_menu > li > a").removeClass("open_toggle_menu");
          submenu.slideDown(300);
          parentA.addClass("open_toggle_menu");
        }
      }
    });
  });
</script>