<?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 blogging_hub
 */

?>
<!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', 'blogging-hub' ); ?></a>

	<?php if( is_front_page() || !is_paged() ) {
		get_template_part( 'apex-library/header', 'image' );
	} ?>

	<?php
		$blogging_hub_facebook_url = get_theme_mod('blogging_hub_facebook_url');
		$blogging_hub_twitter_url = get_theme_mod('blogging_hub_twitter_url');	
		$blogging_hub_instagram_url = get_theme_mod('blogging_hub_instagram_url');
		$blogging_hub_youtube_url = get_theme_mod('blogging_hub_youtube_url');
		$blogging_hub_linkedin_url = get_theme_mod('blogging_hub_linkedin_url');
		$blogging_hub_pinterest_url = get_theme_mod('blogging_hub_pinterest_url');
		$blogging_hub_topbar_email = get_theme_mod('blogging_hub_topbar_email');
	?>

	<section id="upper-header">
		<div class="container topbar">
			<div class="row">
				<div class="col-lg-6 col-md-8 col-12 col-sm-12 align-self-center">
					<div class="topbar-left d-flex text-md-start text-center align-items-center gap-5">

						<!-- DATE -->
						<span class="topbar-date">
							<i class="fa-solid fa-calendar me-1"></i>
							<?php echo esc_html( date_i18n('d - M - Y') ); ?>
						</span>

						<!-- EMAIL -->
						<?php if ($blogging_hub_topbar_email) : ?>
							<span class="topbar-email">
								<i class="fa-solid fa-envelope me-1"></i>
								<a href="mailto:<?php echo esc_attr($blogging_hub_topbar_email); ?>">
									<?php echo esc_html($blogging_hub_topbar_email); ?>
								</a>
							</span>
						<?php endif; ?>

					</div>
				</div>
				<div class="col-lg-6 col-md-4 col-12 col-sm-12 align-self-center social-links text-md-end text-center">
					<?php if( $blogging_hub_facebook_url ){ ?>
	                    <a href="<?php echo esc_url($blogging_hub_facebook_url); ?>"><i class="bi bi-facebook"></i></a>
	                <?php }?>
	                <?php if( $blogging_hub_twitter_url ){ ?>
	                    <a href="<?php echo esc_url($blogging_hub_twitter_url); ?>"><i class="bi bi-twitter-x"></i></a>
	                <?php }?>
	                <?php if( $blogging_hub_instagram_url ){ ?>
	                    <a href="<?php echo esc_url($blogging_hub_instagram_url); ?>"><i class="bi bi-instagram"></i></a>
	            	<?php }?>
	                <?php if( $blogging_hub_youtube_url ){ ?>
	                    <a href="<?php echo esc_url($blogging_hub_youtube_url); ?>"><i class="bi bi-youtube"></i></a>
	            	<?php }?>
	            	<?php if( $blogging_hub_linkedin_url ){ ?>
	                    <a href="<?php echo esc_url($blogging_hub_linkedin_url); ?>"><i class="bi bi-linkedin"></i></a>
	            	<?php }?>
	            	<?php if( $blogging_hub_pinterest_url ){ ?>
	                    <a href="<?php echo esc_url($blogging_hub_pinterest_url); ?>"><i class="bi bi-pinterest"></i></a>
	            	<?php }?>
				</div>
			</div>
		</div>
	</section>

	<header id="masthead" class="site-header">
		<section id="top-header">
			<div class="container">
				<div class="row header-bg">
					<div class="col-xxl-3 col-xl-3 col-lg-3 col-md-4 col-6 align-self-center">
						<div class="site-branding text-center text-md-start">
							<div class="site-branding-logo">
								<?php the_custom_logo(); ?>
							</div>

							<div class="site-branding-text">
								<?php if ( is_front_page() ) : ?>
									<h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
								<?php else : ?>
									<p class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></p>
								<?php endif; ?>

								<?php
								$blogging_hub_description = get_bloginfo( 'description', 'display' );

								if ( $blogging_hub_description || is_customize_preview() ) :
									?>
									<p class="site-description"><?php echo esc_html( $blogging_hub_description ); ?></p>
								<?php endif; ?>
							</div>
						</div>
					</div>
					<div class="col-xxl-7 col-xl-7 col-lg-7 col-md-4 col-3 align-self-center text-md-start">
						<?php get_template_part('apex-library/template-parts/navigation'); ?>
					</div>
					<div class="col-xxl-2 col-xl-2 col-lg-2 col-md-4 col-3 align-self-center search-header text-md-end text-center">
						<?php
						$blogging_hub_blog_hero_enable = get_theme_mod('blogging_hub_header_search_hide', false);

						if ($blogging_hub_blog_hero_enable) : ?>
							<!-- Search Icon -->
							<div id="search-icon" aria-label="Open search" tabindex="0">
								<i class="bi bi-search"></i>
							</div>

							<!-- Search Popup Modal -->
							<div id="search-popup" class="search-popup" role="dialog" aria-modal="true" aria-label="Search form">
								<div class="search-popup-content">
									<button class="close-popup" aria-label="Close search popup">&times;</button>
									<!-- Change span to button for proper accessibility -->
									<div class="search-popup-content">
										
										<?php get_search_form(); ?>
									</div>
								</div>
							</div>
						<?php endif; ?>
					</div>
				</div>
			</div>
		</section>
	</header>

	<div id="content" class="site-content">
