<?php
/**
  * Ahead WebSoft Technologies Pvt Ltd.
  * @copyright  Copyright 2006-2026 Ahead WebSoft Technologies Pvt Ltd.
  * @license    https://www.socialengine.com/policies
*/
?>
<header class="sunshine_header">
	<div class="sunshine_header_container">
  	<div class="header-top">
    	<div class="header_logo">
      	<?php if(engine_in_array('logo',$this->options)){ ?>
        	<?php echo $this->content()->renderWidget("core.menu-logo",array("logo"=>$this->logo)); 
         } ?>
      </div>
      <?php if(engine_in_array('search',$this->options)){ ?>
				<div class="header_search">
					<div class="search_toggle">
						<div class="search_button">
							<a href="javascript:void(0)">  
								<i class="fa fa-search" aria-hidden="true"></i>
							</a>
						</div>
					</div>
					<?php echo $this->content()->renderWidget("core.search-mini"); ?>
				</div>
      <?php } ?>
      <?php if(engine_in_array('miniMenu',$this->options)){ ?>
				<div class="header_menu_mini">
					<?php echo $this->content()->renderWidget("core.menu-mini"); ?>
				</div>
      <?php } ?>
   </div> 
	</div>
   <?php if(engine_in_array('mainMenu',$this->options)){ ?>
      <?php if($this->menuType == 'horizontal') { ?>
        <div class="sunshine_main_menu">
         <div class="navigation_button">
           <button type="button" class="toggle_button"><i class="fas fa-bars"></i></button>
         </div>
          <div class="sunshine_main_menu_container">
            <ul class="navigation">
              <?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="menu_icon <?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">
                        <?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="menu_icon <?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 else:?>
                  <?php break;?>
                <?php endif;?>
                <?php $countMenu++;?>
              <?php endforeach; ?>
              <?php if (engine_count($this->navigation) > $this->menuCount):?>
                <?php $countMenu = 0; ?>
                <li class="more_tab">
                  <a href="javascript:void(0);">
                    <span><?php echo $this->translate("More") ?></span>
                    <i class="fa fa-angle-down open_submenu"></i>
                  </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="menu_icon <?php echo $link->get('icon') ? $link->get('icon') : 'fa fa-star' ?>"></i>
                            <span><?php echo $this->translate($link->getlabel()) ?>
                              <?php if(engine_count($menuSubArray) > 0 && $this->submenu): ?>
                                 
                              <?php endif; ?>
                            </span>
                             <i class="fa fa-angle-down open_submenu"></i>
                          </a>
                          <?php if(engine_count($menuSubArray) > 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="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="menu_icon <?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 endif;?>
                      <?php $countMenu++;?>
                    <?php endforeach; ?>
                  </ul>
                </li>
              <?php endif;?>
            </ul>
          </div>
       </div>
     <?php } ?>
   <?php } ?>
	<?php if(engine_in_array('mainMenu',$this->options)){ ?>
    <?php if($this->menuType == 'vertical') { ?>		
  		<div class="navigation_button">
  			<button type="button" class="toggle_button" data-bs-dismiss="offcanvas" aria-label="Close"><i class="fas fa-bars"></i></button>
  		</div>
     	<div class="header_left_panel">
     		<ul class="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; ?>  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>
    <?php } ?>    
	<?php } ?>
</header>

<script type="text/javascript">
  <?php if($this->menuType == 'vertical') { ?>
   // Main Menu Toggle
    en4.core.runonce.add(function() {
      scriptJquery(".sunshine_header  .toggle_button  ").click(function () {
        if(scriptJquery(".sunshine_header .header_left_panel").hasClass('header-nav-open')){
          scriptJquery(".sunshine_header .header_left_panel").removeClass('header-nav-open')
        }
        else{
          scriptJquery(".sunshine_header .header_left_panel").addClass('header-nav-open');
        }
      });
    });

    scriptJquery(document).click(function(event) {
      if (!scriptJquery(event.target).closest(".sunshine_header .header_left_panel,.sunshine_header .toggle_button ").length) {
        scriptJquery("html").find(".sunshine_header .header_left_panel").removeClass("header-nav-open");
        scriptJquery("html").find("body").removeClass("header-open");
      }
      if (!scriptJquery(event.target).hasClass(".open_submenu").length) {
        scriptJquery('.has_submenu').parent().find('ul').slideToggle('slow');
        scriptJquery('.has_submenu').removeClass('has_submenu');
      }

    });
    en4.core.runonce.add(function() {
      scriptJquery(".sunshine_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;
    });
    en4.core.runonce.add(function() {
      var selectedMenu = scriptJquery('.main_menu_navigation').find(".selected_sub_main_menu");
      if(selectedMenu.length){
        var parentMenu = selectedMenu.closest(".main_menu_submenu").closest("li");
        if(parentMenu.length && !parentMenu.hasClass("active")){
          parentMenu.addClass("active");
        }
      }
      selectedMenu = scriptJquery('.main_menu_navigation').find(".more_tab > ul > li.active");
      if(selectedMenu.length){
        selectedMenu.closest(".more_tab").addClass("active");
      }
    });
   <?php } ?>
   <?php if($this->menuType == 'horizontal') { ?>
   // Main Menu Toggle
    en4.core.runonce.add(function() {
      scriptJquery(".sunshine_main_menu  .toggle_button  ").click(function () {
        if(scriptJquery(".sunshine_main_menu .sunshine_main_menu_container").hasClass('header-nav-open')){
          scriptJquery(".sunshine_main_menu .sunshine_main_menu_container").removeClass('header-nav-open')
        }
        else{
          scriptJquery(".sunshine_main_menu .sunshine_main_menu_container").addClass('header-nav-open');
        }
      });
    });
   
   scriptJquery(document).click(function(event) {
     if (!scriptJquery(event.target).closest(".sunshine_main_menu .sunshine_main_menu_container , .sunshine_main_menu .toggle_button ").length) {
      scriptJquery("html").find(".sunshine_main_menu .sunshine_main_menu_container ").removeClass("header-nav-open");
      scriptJquery("html").find("body").removeClass("header-open");
     }

     if (!scriptJquery(event.target).hasClass(".open_submenu").length) {
        scriptJquery('.has_submenu').parent().find('ul').slideToggle('slow');
        scriptJquery('.has_submenu').removeClass('has_submenu');
      }
   });
   en4.core.runonce.add(function() {
     scriptJquery(".sunshine_main_menu .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;
   });
   // Add Class Search
   en4.core.runonce.add(function() {
   scriptJquery(".header_search").addClass("search_mobile");
   });
  <?php } ?>
   // Header Spacing
   en4.core.runonce.add(function() {
      var height = scriptJquery(".layout_page_header").height();
      if(document.getElementById("global_wrapper")) {
         scriptJquery("#global_wrapper").css("margin-top", height+"px");
      }
   });   

   // Search Toggle
    var removeClass = true;
     scriptJquery(".search_button").click(function () {
     scriptJquery(".header_search .layout_core_search_mini").toggleClass('active');
      removeClass = false;
   });
   
   scriptJquery(".header_search .layout_core_search_mini").click(function() {
    removeClass = false;
   });
   
   scriptJquery("html").click(function () {
    if (removeClass) {
        scriptJquery(".header_search .layout_core_search_mini").removeClass('active');
    }
    removeClass = true;
   });

   // Main Menu Tooltip
  var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
  var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
    return new bootstrap.Tooltip(tooltipTriggerEl)
  });
</script>
