<?php
/**
 * The header for our theme
 *
 * This is the template that displays all of the <head> section and everything up until <div id="content">
 *
 * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
 *
 * @package Spiral_Lite_One_Page
 */

?>
<!doctype html>
<html <?php language_attributes(); ?>>
<head>
	<meta charset="<?php bloginfo( 'charset' ); ?>">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="profile" href="https://gmpg.org/xfn/11">

	<?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>
<?php wp_body_open(); ?>
	<a class="skip-link screen-reader-text" href="#primary"><?php esc_html_e( 'Skip to content', 'spiral-lite-one-page' ); ?></a>


    <?php 
                    $enabled_sections = spiral_lite_one_page_get_sections();
                    $home_link_label  = get_theme_mod( 'spiral_lite_one_page_home_link_label', __( 'Home', 'spiral-lite-one-page' ) );
                    $ed_section_menu  = get_theme_mod( 'spiral_lite_one_page_ed_secion_menu' );

                    
                    if( $enabled_sections && ( 'page' == get_option( 'show_on_front' ) ) && ( $ed_section_menu != 1 ) ){ 
                ?>
                 	<nav id="nav" class="light navbar navbar-expand-lg">
                     <div class="container">

                      <!-- Logo -->
                    <?php $custom_logo_id = get_theme_mod( 'custom_logo' );
                    $logo = wp_get_attachment_image_src( $custom_logo_id , 'full' );
                    if ( has_custom_logo() ) {
                        echo '<a class="logo" href="' . esc_url( home_url( '/' ) ) . '">
                    <img src="' . esc_url( $logo[0] ) . '" alt="' . esc_attr( get_bloginfo( 'name' ) ) . '">
                </a>';
                    } else {
                        echo '<a href="' . esc_url( home_url( '/' ) ) . '"><h3 class="test-logo">' . get_bloginfo('name') . '</h3></a>'; 
                    } ?>
                          <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
                aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                <span class="icon-bar"><i class="fa fa-bars"></i></span>
            </button>
                           
            <!--main navigation-->
            <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <button class="close-menu" aria-label="Close Menu"><i class="fa fa-close"></i></button> <!-- Close button -->
                  <ul id="primary-menu" class="navbar-nav ml-auto">
                      <?php 
                            // Get the home link label from Customizer settings
                            $home_link_label = get_theme_mod( 'spiral_lite_one_page_home_link_label', __( 'Home', 'spiral-lite-one-page' ) );

                            // Check if the home link is enabled
                            if( ! get_theme_mod( 'spiral_lite_one_page_ed_home_link' ) ) {
                            if( is_front_page() ) { ?>
                                <li class="current-menu-item">
                                    <a href="<?php echo esc_url( home_url( '#primary' ) ); ?>"><?php echo esc_html( $home_link_label ); ?></a>
                                </li>
                            <?php } else { ?>
                                <li>
                                    <a href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php echo esc_html( $home_link_label ); ?></a>
                                </li>
                            <?php }
                            }

                            // Get the enabled sections
                            $enabled_sections = spiral_lite_one_page_get_sections();

                            // Loop through the enabled sections and display their menu titles
                            foreach( $enabled_sections as $section ) {
                            if( $section['menu_text'] ) { ?>
                                <li>
                                    <a href="<?php echo esc_url( home_url( '#' . esc_attr( $section['id'] ) ) ); ?>"><?php echo esc_html( $section['menu_text'] ); ?></a>
                                </li>
                            <?php }
                            }

                            ?>
                            </ul>
                                <?php do_action( 'spirallite_social_top' ); ?>
                            </div>

                        </div>
                    </nav>
                <?php }else{ ?>
                    <nav id="nav" class="light navbar navbar-expand-lg">
				  <div class="container">

		 <!-- Logo -->
		 <?php $custom_logo_id = get_theme_mod( 'custom_logo' );
		$logo = wp_get_attachment_image_src( $custom_logo_id , 'full' );
		if ( has_custom_logo() ) {
			echo '<a class="logo" href="' . esc_url( home_url( '/' ) ) . '">
        <img src="' . esc_url( $logo[0] ) . '" alt="' . esc_attr( get_bloginfo( 'name' ) ) . '">
      </a>';
		} else {
			echo '<a href="' . esc_url( home_url( '/' ) ) . '"><h3 class="test-logo">' . get_bloginfo('name') . '</h3></a>'; 
		} ?>

		
			 <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
                aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                <span class="icon-bar"><i class="fa fa-bars"></i></span>
            </button>
			
			<!--main navigation-->
			<div class="collapse navbar-collapse" id="navbarSupportedContent">
            <button class="close-menu" aria-label="Close Menu">✖</button> <!-- Close button -->
			<?php 
				wp_nav_menu(
					array(
						'theme_location' => 'menu-1',
						'container'      => 'ul',
						'menu_id'        => 'primary-menu',
						'menu_class'     => 'navbar-nav ml-auto',
						'fallback_cb'    => 'spiral_lite_one_page_custom_menu_fallback',
					)
				);
			?>

			<?php do_action( 'spirallite_social_top' ); ?>
		    	</div><!-- #end-main navigation -->
			</div><!-- #end-container -->
		</nav><!-- #site-navigation -->

                <?php } ?>
	