<?php
/**
 * The template used for displaying hero content
 *
 * @package Signify
 */

$signify_type  = get_theme_mod( 'signify_hero_content_type', 'page' );
$signify_title = get_theme_mod( 'signify_display_hero_content_title', 1 );
$sub_title     = get_theme_mod( 'signify_hero_content_sub_title' );
$style         = get_theme_mod( 'signify_hero_content_style', 'style-one' );

if ( 'page' === $signify_type && $signify_id = get_theme_mod( 'signify_hero_content' ) ) {
	$args['page_id'] = absint( $signify_id );
} elseif ( 'post' === $signify_type && $signify_id = get_theme_mod( 'signify_hero_content_post' ) ) {
	$args['p'] = absint( $signify_id );
} elseif ( 'category' === $signify_type && $signify_cat = get_theme_mod( 'signify_hero_content_category' ) ) {
	$args['cat'] = absint( $signify_cat );
	$args['posts_per_page'] = 1;
}

// If $args is empty return false
if ( empty( $args ) ) {
	return;
}

$classes[] = 'hero-section';
$classes[] = 'section';
$classes[] = get_theme_mod( 'signify_hero_content_img_align', 'content-align-right' );
$classes[] = get_theme_mod( 'signify_hero_content_txt_align', 'text-align-left' );
$classes[] = $style;

if( ! $signify_title && ! $sub_title ) {
	$classes[] = 'no-section-heading';
}

// Create a new WP_Query using the argument previously created
$hero_query = new WP_Query( $args );
if ( $hero_query->have_posts() ) :
	while ( $hero_query->have_posts() ) :
		$hero_query->the_post();
		?>
		<div id="hero-section" class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>">
			<div class="wrapper">
				<div class="section-content-wrapper hero-content-wrapper">
					<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
						<div class="hentry-inner">
							<?php $post_thumbnail = signify_post_thumbnail( 'post-thumbnail', 'html-with-bg', false ); // signify_post_thumbnail( $image_size, $signify_type = 'html', $echo = true, $no_thumb = false ).

						if ( $post_thumbnail ) :
							echo $post_thumbnail;
							?>
							<div class="entry-container">
						<?php else : ?>
							<div class="entry-container full-width">
						<?php endif;
						
						if ( 'style-two' === $style ) : ?>
							<div class="content-wrapper"> 
							<?php endif;

							if ( $signify_title || $sub_title ) : ?>
								<header class="entry-header">
									<?php if ( $sub_title ) : ?>
										<div class="section-subtitle">
											<?php
											echo esc_html( $sub_title );
											?>
										</div><!-- .section-description-wrapper -->
									<?php endif; ?>
									<?php if ( $signify_title ) : ?>
									<h2 class="entry-title section-title">
										<?php the_title(); ?>
									</h2>
									<?php endif; ?>
								</header><!-- .entry-header -->
							<?php endif; ?>

							<div class="entry-content">
								<?php

									$show_content = get_theme_mod( 'signify_hero_content_show', 'excerpt' );

									if ( 'full-content' === $show_content ) {
										the_content();
									} elseif ( 'excerpt' === $show_content ) {
										the_excerpt();
									}

									wp_link_pages( array(
										'before'      => '<div class="page-links"><span class="page-links-title">' . esc_html__( 'Pages:', 'signify-pro' ) . '</span>',
										'after'       => '</div>',
										'link_before' => '<span class="page-number">',
										'link_after'  => '</span>',
										'pagelink'    => '<span class="screen-reader-text">' . esc_html__( 'Page', 'signify-pro' ) . ' </span>%',
										'separator'   => '<span class="screen-reader-text">, </span>',
									) );
								?>
							</div><!-- .entry-content -->

							<?php if ( get_edit_post_link() ) : ?>
								<footer class="entry-footer">
									<div class="entry-meta">
										<?php
											edit_post_link(
												sprintf(
													/* translators: %s: Name of current post */
													esc_html__( 'Edit %s', 'signify-pro' ),
													the_title( '<span class="screen-reader-text">"', '"</span>', false )
												),
												'<span class="edit-link">',
												'</span>'
											);
										?>
									</div>	<!-- .entry-meta -->
								</footer><!-- .entry-footer -->
							<?php endif;

							if ( 'style-two' === $style ) : ?>
							</div><!-- .content-wrapper -->
								<?php endif; ?>
							</div><!-- .entry-container -->
						</div><!-- .hentry-inner -->
					</article>
				</div><!-- .section-content-wrapper -->
			</div><!-- .wrapper -->
		</div><!-- .section -->
	<?php
	endwhile;

	wp_reset_postdata();
endif;
