<!DOCTYPE html>
<html <?php language_attributes(); ?>>
    <head>
        <meta charset="<?php bloginfo( 'charset' ); ?>" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <link rel="profile" href="http://gmpg.org/xfn/11" />
        <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
        <?php wp_head(); ?>
    </head>
    <body <?php body_class(); ?>>
        
        <header>
            <?php

                global $wp_customize, $mythemes_header_class;
                $show_header    = false;

                /* FRONT PAGE */
                $on_front_page          = get_theme_mod( 'header-front-page', true );
                $is_enb_front_page      = get_option( 'show_on_front' ) == 'page';
                $is_front_page          = $is_enb_front_page && is_front_page();

                /* BLOG PAGE */
                $on_blog_page           = get_theme_mod( 'header-blog-page', true );

                if( $is_enb_front_page ){
                    $is_blog_page = is_home();
                }
                else{
                    $is_blog_page = is_front_page();
                }

                if( $is_front_page && $on_front_page ){
                    $show_header = true;
                    $mythemes_header_class = 'on-front-page';
                }
                else if( $is_front_page && !$on_front_page ){
                    $show_header = false;
                    $mythemes_header_class = 'on-front-page';   
                }
                else if( $is_blog_page && $on_blog_page ){
                    $show_header = true;
                    $mythemes_header_class = 'on-blog-page';
                }
                else if( $is_blog_page && !$on_blog_page ){
                    $show_header = false;
                    $mythemes_header_class = 'on-blog-page';
                }
                else if( is_singular( 'post' ) ){
                    $show_header = get_theme_mod( 'header-single-posts', true );
                    $mythemes_header_class = 'on-single-posts';
                }
                else if( is_singular( 'page' ) && ! $is_front_page ){
                    $show_header = get_theme_mod( 'header-single-pages', true );
                    $mythemes_header_class = 'on-single-pages';
                }
                else{
                    $show_header = get_theme_mod( 'header-templates', true );
                    $mythemes_header_class = 'on-templates';
                }

                /* CUSTOMIZER */
                if( isset( $wp_customize ) ) {
                    if( !$show_header ){
                        $mythemes_header_class .= ' hidden';
                        $show_header = true;
                    }
                }

                if( $show_header ){
                    get_template_part( 'templates/header' );
                }
            ?>

            <div class="mythemes-poor">
                <div class="container">

                    <div class="row mythemes-nav-small-device">
                        <div class="col-xs-9 col-sm-9 col-md-9 col-lg-9 mythemes-nav-label">
                            <?php
                                $blog_title         = get_bloginfo( 'name' );
                                $blog_description   = get_bloginfo( 'description' );
                            ?>
                            <a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( $blog_title . ' - ' . $blog_description  ) ?>">
                                <?php echo esc_html( $blog_title ); ?>
                            </a>
                        </div>
                        <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 mythemes-nav-btn">
                            <button type="button" class="btn-collapse btn-base-nav" data-toggle=".header-nav.base-nav">
                                <i>+</i>
                            </button>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-sm-12 col-md-12 col-lg-12">
                            <nav class="mythemes-nav-inline base-nav header-nav nav-collapse">

                            <?php
                                $args = array(
                                    'theme_location'    => 'header',
                                    'container_class'   => 'nav-wrapper',
                                    'menu_class'        => 'mythemes-menu'
                                );
                                
                                $location = get_nav_menu_locations();
                                if( isset( $location[ 'header' ] ) && $location[ 'header' ] > 0 ){
                                    wp_nav_menu( $args );
                                }else{
                                    $pages = get_posts( array(
                                        'numberposts' => 7,
                                        'post_type' => 'page',
                                        'order' => 'ASC'
                                    ) );
                                    
                                    if( !empty( $pages ) ){
                                        echo '<div class="nav-wrapper">';
                                        echo '<ul class="mythemes-menu">';

                                        foreach( $pages as $p => $item ){
                                            $classes = '';
                                            if( is_page( $item -> ID ) )
                                                $classes = 'current-menu-item';
                                                
                                            echo '<li class="menu-item ' . $classes . '">';
                                            echo '<a href="' . esc_url( get_permalink( $item -> ID ) ) . '" title="' . mythemes_post::title( $item -> ID, true ) . '">' . mythemes_post::title( $item -> ID ) . '</a></li>';
                                        }
                                        echo '</ul>';
                                        echo '</div>';
                                    }
                                }
                            ?>
                            </nav>

                        </div>

                    </div>

                </div>
            </div>

        </header>