<?php
/**
 * Page header template
 *
 * @package Multi
 */

?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>
<?php if ( get_theme_mod( 'multi_customize_scrollbars', MULTIMAGAZINE_CUSTOMIZE_SCROLLBARS ) ) : ?>
	class="custom-scrollbars no-scroll"
<?php else : ?>
	class="no-scroll"
<?php endif; ?>
>
<head>
	<meta charset="<?php bloginfo( 'charset' ); ?>">
	<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
	<?php wp_head(); ?>
</head>
<?php

$multimagazine_mobile_pull_down_default = get_theme_mod( 'multi_menu_pulldown_closed', MULTIMAGAZINE_MENU_PULLDOWN_CLOSED );
if ( empty( $multimagazine_mobile_pull_down_default ) ) {
	$multimagazine_mobile_pull_down_default = MULTIMAGAZINE_MENU_PULLDOWN_CLOSED;
}
$multimagazine_mobile_pull_down_expanded = get_theme_mod( 'multi_menu_pulldown_expanded', MULTIMAGAZINE_MENU_PULLDOWN_EXPANDED );
if ( empty( $multimagazine_mobile_pull_down_expanded ) ) {
	$multimagazine_mobile_pull_down_expanded = MULTIMAGAZINE_MENU_PULLDOWN_EXPANDED;
}
?>

<body <?php body_class(); ?>
	data-pulldown-default="<?php echo esc_attr( 'm-icon-' . $multimagazine_mobile_pull_down_default ); ?>"
	data-pulldown-expanded="<?php echo esc_attr( 'm-icon-' . $multimagazine_mobile_pull_down_expanded ); ?>"
	<?php
	$multimagazine_maps_api_key = get_theme_mod( 'multi_map_api_key', '' );
	if ( ! empty( $multimagazine_maps_api_key ) ) :
		?>
		data-mapsapikey="<?php echo esc_attr( $multimagazine_maps_api_key ); ?>"
		<?php
		endif;
	?>
	>
	<?php wp_body_open(); ?>
	<a href="#site-content" class="skip-link"><?php esc_html_e( 'Skip to content', 'multimagazine' ); ?></a>
	<?php
	if ( get_theme_mod( 'multi_preloader', MULTIMAGAZINE_PRELOADER ) ) {
		get_template_part( 'template-parts/preloader' );
	}
	if ( get_theme_mod( 'multi_cursor', MULTIMAGAZINE_CURSOR ) ) {
		get_template_part( 'template-parts/cursor' );
	}
	?>

	<?php do_action( 'multimagazine_page_start' ); ?>

	<div class="root" id="top">

	<?php do_action( 'multimagazine_before_header' ); ?>

	<?php
	$sticky_header_mode = get_theme_mod( 'multi_sticky_header', MULTIMAGAZINE_STICKY_HEADER );
	$sticky_mobile      = get_theme_mod( 'multi_sticky_header_mobile', MULTIMAGAZINE_STICKY_HEADER_MOBILE );
	$fullwidth_header   = get_theme_mod( 'multi_fullwidth_header', MULTIMAGAZINE_FULLWIDTH_HEADER );
	$show_subheader     = get_theme_mod( 'multi_show_subheader', MULTIMAGAZINE_SHOW_SUBHEADER ) ? 'on' : 'off';

	/**
	 * Single post header
	 */
	$special_header_enabled = false;
	$special_header_mobile  = false;
	if ( is_single() ) {
		$special_header_enabled = get_theme_mod( 'multi_post_header', MULTIMAGAZINE_POST_HEADER );

		if ( $special_header_enabled ) {
			$special_header_mobile = get_theme_mod( 'multi_post_header_mobile', MULTIMAGAZINE_POST_HEADER_MOBILE );
			get_template_part( 'template-parts/header-single' );
			if ( ! $special_header_mobile && $sticky_mobile ) {
				$classes[] = 'mobile-sticky';
			}
		}
	}

	/**
	 * Feature classes for header
	 */
	$classes = array( 'site-header' );
	if ( get_theme_mod( 'multi_header_shadow', MULTIMAGAZINE_HEADER_SHADOW ) ) {
		$classes[] = 'header-shadow';
	}
	if ( get_theme_mod( 'multi_sticky_header_shadow', MULTIMAGAZINE_STICKY_HEADER_SHADOW ) ) {
		$classes[] = 'sticky-header-shadow';
	}

	if ( 'off' !== $sticky_header_mode && ! $special_header_enabled ) {
		$classes[] = 'sticky-enabled';
		$classes[] = $sticky_header_mode;
	}
	if ( $sticky_mobile && ! $special_header_mobile ) {
		$classes[] = 'mobile-sticky';
	}
	if ( $fullwidth_header ) {
			$classes[] = 'full-width';
	}

	$header_with_image = false;

	$header_mode = '';
	if ( is_single() || is_page() ) {
		$header_mode = get_post_meta( get_the_id(), 'multi_header_style', true );
		if ( ! empty( $header_mode ) ) {
			$classes[] = $header_mode;
		}
		$show_subheader = get_post_meta( get_the_id(), 'multi_show_subheader', true );
		if ( empty( $show_subheader ) ) {
			$show_subheader = get_theme_mod( 'multi_show_subheader', MULTIMAGAZINE_SHOW_SUBHEADER ) ? 'on' : 'off';
		}

		$multimagazine_post_layout = get_post_meta( get_the_id(), 'multi_post_layout', true );
		if ( empty( $multimagazine_post_layout ) ) {
			$multimagazine_post_layout = get_theme_mod( 'multi_post_layout', MULTIMAGAZINE_POST_LAYOUT );
		}
		$header_with_image = 'full-width-header-image' === $multimagazine_post_layout;
	}


	if ( 'off' !== $header_mode ) :
		$header_classes = implode( ' ', $classes );
		?>
		<?php
		if ( get_theme_mod( 'multi_show_topbar', MULTIMAGAZINE_SHOW_TOPBAR ) ) {
			get_template_part( 'template-parts/top-bar' );
		}
		?>
	<header class="<?php echo esc_attr( $header_classes ); ?>">
		<?php
		do_action( 'multimagazine_header_start' );
		get_template_part( 'template-parts/header' );
		?>
	</header>
		<?php
	endif;
	?>
	<div class="content-start"></div>
	<?php

	/**
	 *  Content start
	 */
	$args = array( 'show_subheader' => $show_subheader );
	get_template_part( 'template-parts/subheader', null, $args );

	if ( ! is_404() && ! $header_with_image && ! multimagazine_breadcrumbs_in_subheader_pos() && 'off' !== get_post_meta( get_the_id(), 'multi_show_breadcrumbs', true ) ) {
		do_action( 'multimagazine_breadcrumbs' );
	}
	?>

<?php do_action( 'multimagazine_sliders' ); ?>

<?php
/**
 * Revolution slider
 */
if ( ! is_search() && ! is_404() && get_post() && class_exists( 'RevSliderFront' ) ) {
	$revolution_slider = get_post_meta( $post->ID, 'multi_revolution_slider', true );
	if ( $revolution_slider ) :
		?>
		<div class="revolution-slider">
		<?php
		if ( is_front_page() ) {
			putRevSlider( $revolution_slider, 'Homepage' );
		} else {
			putRevSlider( $revolution_slider, get_the_ID() );
		}
		?>
		</div>
		<?php
	endif;
} /** Revolution slider end */
