<?php
// Offcanvas Menu
if (!function_exists('newsxo_sidebar_menu_function')):
  function newsxo_sidebar_menu_function() { 
    $newsxo_menu_sidebar  = get_theme_mod('newsxo_menu_sidebar',true); 
    if($newsxo_menu_sidebar == true){ ?>
    <!-- Off Canvas -->
      <div class="hedaer-offcanvas d-none d-lg-block">
        <button class="offcanvas-trigger" bs-data-clickable-end="true">
          <i class="fa-solid fa-bars-staggered"></i>
        </button>
      </div>
    <!-- /Off Canvas -->
    <?php } ?>

  <?php }
endif;
add_action('newsxo_action_sidebar_menu_function', 'newsxo_sidebar_menu_function', 5);

// Dar/Light Switch
if (!function_exists('newsxo_header_dark_switch_section')) :

  function newsxo_header_dark_switch_section() {
    $newsxo_lite_dark_switcher = get_theme_mod('newsxo_lite_dark_switcher', true);
    if($newsxo_lite_dark_switcher == true){ 
      if ( isset( $_COOKIE["newsxo-site-mode-cookie"] ) ) {
        $newsxo_skin_mode = $_COOKIE["newsxo-site-mode-cookie"];
      } else {
        $newsxo_skin_mode = get_theme_mod( 'newsxo_skin_mode', 'defaultcolor' );
      } ?>
      <label class="switch d-none d-lg-inline-block" for="switch">
        <input type="checkbox" name="mode-switch" data-toggle="mode-switcher" id="mode-switcher" class="<?php echo esc_attr( $newsxo_skin_mode ); ?>" data-skin-mode="<?php echo esc_attr( $newsxo_skin_mode ); ?>">
      </label>
    <?php } 
  }
endif;
add_action('newsxo_action_header_dark_switch_section', 'newsxo_header_dark_switch_section', 5);

// Search
if (!function_exists('newsxo_header_search_section')) :

  function newsxo_header_search_section() { 
    $newsxo_menu_search  = get_theme_mod('newsxo_menu_search',true);
    if($newsxo_menu_search == true) { ?>
      <!-- search-->
      <a class="msearch element" href="#" bs-search-clickable="true">
        <i class="fa-solid fa-magnifying-glass"></i>
      </a>
      <!-- /search-->
    <?php } 
  }
endif;
add_action('newsxo_action_header_search_section', 'newsxo_header_search_section', 5);

// Subscriber Button
if (!function_exists('newsxo_header_subs_section')) :

  function newsxo_header_subs_section() {  
    $subsc_link = get_theme_mod('newsxo_subsc_link', '#'); 
    $newsxo_menu_subscriber  = get_theme_mod('newsxo_menu_subscriber',true);
    $subsc_icon  = get_theme_mod('subsc_icon_layout','bell');
    $subsc_open_in_new  = get_theme_mod('subsc_open_in_new',true) == true ? ' target="_blank"' : '';
    $subs_title  = get_theme_mod('subs_news_title','Subscribe');
    if($newsxo_menu_subscriber == true) { ?> 
    <a href="<?php echo esc_attr($subsc_link) ?>" class="subscribe-btn btn btn-five d-flex" data-text="<?php echo $subs_title; ?>" <?php echo $subsc_open_in_new ?>>
      <i class="fas fa-<?php echo esc_html($subsc_icon) ?>"></i> <?php if(!empty($subs_title)){ echo '<span>'.$subs_title.'</span>';  } ?>
    </a>
    <?php }
  }
endif;
add_action('newsxo_action_header_subs_section', 'newsxo_header_subs_section', 5);

// Woo Cart

if (!function_exists('newsxo_header_woo_cart_section')) :

  function newsxo_header_woo_cart_section() {
    if( class_exists( 'WooCommerce' ) ) {
      $enable_cart  = get_theme_mod('newsxo_cart_enable',1);
      if($enable_cart == 1){ ?>
        <a href="<?php echo esc_url( wc_get_cart_url() ); ?>" class="bs-cart element">
          <span class='bs-cart-total'>
            <?php echo WC()->cart->get_cart_subtotal(); ?>
          </span>
          <span class="bs-cart-icon">
            <i class="fa-solid fa-cart-arrow-down"></i>
          </span>
          <span class='bs-cart-count'>
            <?php echo WC()->cart->get_cart_contents_count(); ?>
          </span>
        </a>
      <?php  
      } 
    } 
  }
endif;
add_action('newsxo_action_header_cart_section', 'newsxo_header_woo_cart_section', 5);

if (!function_exists('newsxo_header_menu_cont_section')) :
/**
 *  Header
 *
 * @since newsxo
 *
 */
function newsxo_header_menu_cont_section() {
  
  $header_menu_layout = get_theme_mod('header_menu_layout','default');
  $home_icon_disable = get_theme_mod('newsxo_home_icon',true); ?>
  <!-- Header bottom -->
    <?php $sticky_header_toggle = get_theme_mod('sticky_header_toggle', true);
      if ($sticky_header_toggle == true) { $sticky_header = get_theme_mod('sticky_header_option', 'default') == 'default' ? ' sticky-header' : ' scroll-up'; } else { $sticky_header =''; } ?>
      <div class="bs-menu-full<?php echo esc_attr($sticky_header); ?>">
        <div class="container">
          <div class="main-nav d-flex align-center"> 
            <?php do_action('newsxo_action_header_menu_section'); 
              do_action('newsxo_action_header_right_menu_section'); 
            ?>
          </div>
        </div>
      </div> 
  <!-- Header bottom -->
<?php  }
endif;
add_action('newsxo_action_header_menu_cont_section', 'newsxo_header_menu_cont_section', 6);


if (!function_exists('newsxo_header_top_section')) :
  /**
   *  Header
   *
   * @since newsxo
   *
   */
  function newsxo_header_top_section(){  ?>
    <!--top-bar-->
    <div class="container">
      <div class="row align-center">
        <!--col-md-5-->
        <div class="col-md-12 col-xs-12">
          <div class="tobbar-right d-flex-space flex-wrap ">
            <?php newsxo_output_repeater('newsxo_header_topbar_repeater'); ?>
          </div>
        </div>
        <!--/col-md-5-->
      </div>
    </div>
    <!--/top-bar-->
    <?php
  }
endif;
add_action('newsxo_action_header_section', 'newsxo_header_top_section', 5);


if (!function_exists('newsxo_header_extra_section')) :
  /**
   *  Header Extra
   *
   * @since Newsxo
   *
   */
  function newsxo_header_extra_section(){
    if (is_front_page() || is_home()) { 
      if ( newsxo_has_repeater_items('newsxo_header_extra_repeater') ) {
        ?>
        <!--==================== EXTRA BAR ====================-->
        <div class="bs-head-extra">
          <div class="container">
            <div class="row align-center">
              <?php newsxo_output_repeater('newsxo_header_extra_repeater'); ?>
            </div>
          </div>
        </div>
        <!--==================== End EXTRA BAR ====================-->
        <?php
      }
    }
  }
endif;
add_action('newsxo_action_header_extra_section', 'newsxo_header_extra_section', 5);