<?php
/**
 * Theme Name:      Noisa
 * Theme Author:    Mariusz Rek - Rascals Themes
 * Theme URI:       http://rascalsthemes.com/noisa
 * Author URI:      http://rascalsthemes.com
 * File:            header.php
 * @package noisa
 * @since 1.0.0
 */

// Get options
$noisa_opts = noisa_opts();

?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<?php 
    // Get panel options
    $noisa_opts = noisa_opts();
?>
<head>
	<meta charset="<?php bloginfo( 'charset' ); ?>">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
	<link rel="profile" href="http://gmpg.org/xfn/11">
	<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
	<?php wp_head(); ?>
</head>
<?php 
$page_id = '0';

if ( isset( $wp_query ) && isset( $post ) ) {
    $page_id = $wp_query->post->ID;
}
?>
<body <?php body_class( ) ?> data-page_id="<?php echo esc_attr( $page_id ) ?>" data-wp_title="<?php esc_attr( wp_title( '|', true, 'right' ) ) ?>">

<?php if ( ! is_customize_preview() ) : ?>
    <?php if ( function_exists('noisa_toolkit') && noisa_toolkit() ) : ?>
        <?php echo noisa_wpal_show_loader(); ?>
    <?php endif; ?>
<?php endif; ?>

<div id="slidebar" class="dark-bg">

    <?php if ( get_theme_mod( 'noisa_slidepanel_image', '' )  !== '' ) : ?>
    <div class="slidebar-image" style="background-image:url(<?php echo esc_url( get_theme_mod( 'noisa_slidepanel_image', '' ) ) ?>)"></div>
    <?php endif; ?>

    <a href="#" id="slidebar-close"></a>
    <div id="slidebar-content" class="clearfix dark-bg">
        <div>
            <?php if ( get_theme_mod( 'noisa_slidepanel_search', true ) ) : ?>
            <div id="slidebar-search">
                <?php get_search_form(); ?>
            </div>
            <?php endif; ?>
            <?php
                $defaults = array(
                    'theme_location'  => 'sidebar',
                    'menu'            => '',
                    'container'       => false,
                    'container_class' => '',
                    'menu_class'      => 'menu',
                    'fallback_cb'     => 'wp_page_menu',
                    'depth'           => 4
                );              
            ?>
        
        <nav id="main-nav">
            <?php if ( has_nav_menu( 'sidebar' ) ) : ?>
            <?php wp_nav_menu( $defaults ); ?>
            <?php endif; ?>
        </nav>
            <?php get_sidebar( 'slidebar' ); ?>
        </div>
    </div>

</div>  
<div id="slidebar-layer"></div>

<div id="site" class="site">
    <?php 
    if ( get_theme_mod( 'noisa_always_show_header', false ) === true ) {
        $always_show_header = 'always-show-header';
    } else {
        $always_show_header = '';
    }
     ?>
    <header id="header" class="<?php echo esc_attr( $always_show_header ) ?>">

        <div class="container">

            <div id="site-logo" class="header-logo">
                 <?php noisa_header_logo(); ?>

            </div>
            <nav id="icon-nav">
                <a href="#" class="icon-nav-item" id="menu-trigger"><span class="icon"></span></a>
                <?php if ( get_theme_mod( 'noisa_cart_button', true ) ) : ?>
                    <?php if ( class_exists( 'WooCommerce' ) ) : ?>
                        <?php 
                            $count = WC()->cart->get_cart_contents_count();
                            
                            $wc_link = wc_get_cart_url();
                            if ( get_theme_mod( 'noisa_cart_link', 'shop' ) === 'shop' ) {
                                $wc_link = get_permalink( get_option( 'woocommerce_shop_page_id' ) );
                            } 
                        ?>
                        <a href="<?php echo esc_url( $wc_link ) ?>" id="shop-link" class="icon-nav-item"><span class="icon icon-cart"></span><?php if ( $count > 0 ) { echo "<span class='shop-items-count'>$count</span>"; } ?></a>
                    <?php endif ?>
                <?php endif ?>

            </nav>

            <?php if ( function_exists( 'noisa_social_header_buttons' ) ) : ?>
                <nav id="social-nav">
                    <?php echo noisa_social_header_buttons( get_theme_mod( 'header_social_buttons' ) ); ?>
                </nav>
            <?php endif; ?>

            <?php
            $defaults = array(
                'theme_location'  => 'top',
                'menu'            => '',
                'container'       => false,
                'container_class' => '',
                'menu_class'      => 'menu',
                'fallback_cb'     => 'wp_page_menu',
                'depth'           => 3
            );              
            ?>
            <?php if ( has_nav_menu( 'top' ) ) : ?>
            <nav id="nav"> 
                <?php wp_nav_menu( $defaults ); ?>
            </nav>
        	<?php endif; ?>
        </div>
    </header>

    <div id="ajax-container">
        <div id="ajax-content">