<?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 Moral
 */
?>
<!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 do_action( 'wp_body_open' ); ?>
<div id="page" class="site">
	<a class="skip-link screen-reader-text" href="#content"><?php esc_html_e( 'Skip to content', 'moral-magazine' ); ?></a>
    
    <div class="menu-overlay"></div>
    <?php if ( get_theme_mod( 'moral_magazine_topbar' ) == true ): 
        $top_bar_class = get_theme_mod( 'moral_magazine_topbar_design', 'design-one' ) == 'design-one' ? '' : 'second-design';

        if(!empty(get_option('timezone_string'))){
            $time_zone = new DateTimeZone(get_option('timezone_string'));
        }else{
            if ( get_option('gmt_offset') !== '0' ) {
                $time_zone = new DateTimeZone(get_option('gmt_offset'));
            }else{
                $time_zone = new DateTimeZone('UTC');
            }           
        }
        $datetime = new DateTime("now", $time_zone); 
        $date_format = get_option('date_format');
        $date = $datetime->format($date_format);
    ?>
        <div id="top-navigation" class="relative <?php echo esc_attr( $top_bar_class ); ?>">
            <div class="wrapper">
                <button class="menu-toggle" aria-controls="secondary-menu" aria-expanded="false">
                    <svg viewBox="0 0 40 40" class="icon-menu">
                        <rect y="7" width="40" height="2"></rect>
                        <rect y="19" width="40" height="2"></rect>
                        <rect y="31" width="40" height="2"></rect>
                    </svg>

                    <svg viewBox="0 0 612 612" class="icon-close">
                        <polygon points="612,36.004 576.521,0.603 306,270.608 35.478,0.603 0,36.004 270.522,306.011 0,575.997 35.478,611.397 
                        306,341.411 576.521,611.397 612,575.997 341.459,306.011"></polygon>
                    </svg>
                </button><!-- .menu-toggle -->

                <nav id="secondary-navigation" class="main-navigation" role="navigation" aria-label="Secondary Menu">
                    <?php   

                        $contact_info = '';
                        
                        if ( get_theme_mod( 'moral_magazine_topbar_date', false ) == 'true' ) {

                            $contact_info .= '<li class="contact-info"><span class="posted-on"><span class="screen-reader-text">'.__( 'Posted on', 'moral-magazine' ).'</span>'.$date.'</span></li>';               

                        }

                       
                        if ( get_theme_mod( 'moral_magazine_topbar_social_menu', false ) == true &&  has_nav_menu( 'social' )  ) {
                            
                            $contact_info .= '<li class="social-icons">';               
                   
                            $contact_info .= wp_nav_menu( array(
                                                'theme_location'  => 'social',
                                                'container' => 'ul',
                                                'container_class' => 'menu',
                                                'depth'           => 1,
                                                'echo'            => false,
                                                'link_before'     => '<span class="screen-reader-text">',
                                                'link_after'      => '</span>' . moral_magazine_get_svg( array( 'icon' => 'chain' ) ),
                                            ));
                            $contact_info .= '</li>';
                        }
                        


                        $defaults = array(
                            'theme_location' => 'secondary',
                            'container' => false,
                            'menu_class' => 'menu nav-menu',
                            'menu_id' => 'secondary-menu',
                            'echo' => true,
                            'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s' . $contact_info .'</ul>',
                        );
                        
                        if ( has_nav_menu( 'secondary' )  ){
                            wp_nav_menu( $defaults );
                        }
                        
                    ?>
                    <div class="icon-wrapper">
                        <?php if ( get_theme_mod( 'moral_magazine_topbar_date', false ) == 'true' ) { ?>
                            <div class="contact-info">
                                <div class="entry-meta">
                                    <span class="posted-on">
                                        <span class="screen-reader-text"><?php echo __( 'Posted on', 'moral-magazine' ) ?></span> 
                                        <?php echo esc_html( $date ); ?>
                                    </span><!-- .posted-on -->
                                </div><!-- .entry-meta -->
                            </div>
                        <?php } ?>
                        <?php if ( get_theme_mod( 'moral_magazine_topbar_social_menu', false ) == true &&  has_nav_menu( 'social' )  ): ?>
                            <div class="social-icons">
                                <?php 
                                    wp_nav_menu( array(
                                            'theme_location'  => 'social',
                                            'container' => 'ul',
                                            'container_class' => 'menu',
                                            'link_before'     => '<span class="screen-reader-text">',
                                            'link_after'      => '</span>' . moral_magazine_get_svg( array( 'icon' => 'chain' ) ),
                                        ) ); 
                                ?>
                            </div><!-- .social-icons -->
                        <?php endif ?>
                        
                    </div><!-- .icon-wrapper -->
                </nav><!-- .main-navigation-->            
            </div><!-- .wrapper -->
        </div><!-- #top-navigation -->

    <?php endif ?>

   <?php get_template_part( 'template-parts/header' );  ?>
    
	<div id="content" class="site-content">
