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

$header_type = get_theme_mod( 'header_type', 'type-1' );

$template = 'template-parts/header/' . (
	str_replace(
		'type',
		'header',
		$header_type
	)
);

ob_start();

if ( is_customize_preview() ) {
	$for_preview = true;
	include locate_template( 'template-parts/header/header-1.php' );
	$for_preview = false;
}

$type_1_output = ob_get_clean();

ob_start();

if ( is_customize_preview() ) {
	$for_preview = true;
	include locate_template( 'template-parts/header/header-2.php' );
	$for_preview = false;
}

$type_2_output = ob_get_clean();

blocksy_add_customizer_preview_cache(
	function () use ($type_1_output, $type_2_output) {
		return blocksy_html_tag(
			'div',
			[ 'data-id' => 'header' ],
			blocksy_html_tag( 'div', [ 'data-type' => 'type-1' ], $type_1_output ) .
			blocksy_html_tag( 'div', [ 'data-type' => 'type-2' ], $type_2_output )
		);
	}
);

blocksy_add_customizer_preview_cache(
	function () {
		return blocksy_html_tag(
			'div',
			[ 'data-id' => 'header-top-bar' ],
			blocksy_output_header_top_bar()
		);
	}
);

blocksy_header_top_bar_sections_cache();

?>

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

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

<body <?php body_class(); ?>>
<div id="main-container">

	<header class="site-header" <?php echo blocksy_schema_org_definitions('header') ?>>
		<?php
			if (
				get_theme_mod( 'has_top_bar', 'yes' ) === 'yes' || (
					isset( $for_preview ) && $for_preview
				)
			) {
				echo blocksy_output_header_top_bar();
			}
		?>

		<?php get_template_part( $template ); ?>
		<?php get_template_part( 'template-parts/header/mobile' ); ?>
	</header>

	<main id="main" class="site-main">
