<?php
/**
  * Ahead WebSoft Technologies Pvt Ltd.
  * @copyright  Copyright 2006-2026 Ahead WebSoft Technologies Pvt Ltd.
  * @license    https://www.socialengine.com/policies
*/
?>
<?php $countMenu = 0; ?>
<ul class="harmony_main_menu_nav navigation " id="navigation_menu">
  <?php foreach( $this->navigation as $link ): ?>
    <?php if(!empty($user_front) && $countMenu < $this->menuCount ): ?>
      <?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 && $this->submenu): ?>
            <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 else:?>
      <?php break;?>
    <?php endif;?>
    <?php $countMenu++;?>
  <?php endforeach; ?>
  <?php if (count($this->navigation) > $this->menuCount):?>
    <?php $countMenu = 0; ?>
    <li class="more_tab">
      <a href="javascript:void(0);" class="menu_core_main menu_core_main_more">
        <i class="fi fi-rr-square-plus"></i>
        <span><?php echo $this->translate("More") ?></span>
      </a>
      <ul class="main_menu_submenu">
        <?php foreach( $this->navigation as  $link ): ?>
          <?php if ($countMenu >= $this->menuCount): ?>
            <?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>
              </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 endif;?>
          <?php $countMenu++;?>
        <?php endforeach; ?>
      </ul>
    </li>
  <?php endif;?>
</ul>