<?php
/**
 * The template used for displaying playlist
 *
 * @package Signify
 */
?>

<?php
$enable_section = get_theme_mod( 'signify_playlist_visibility', 'disabled' );

if ( ! signify_check_section( $enable_section ) ) {
	// Bail if playlist is not enabled
	return;
}

$signify_type = get_theme_mod( 'signify_playlist_type', 'page' );

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

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

// Create a new WP_Query using the argument previously created
$playlist_query = new WP_Query( $args );
if ( $playlist_query->have_posts() ) :
	while ( $playlist_query->have_posts() ) :
		$playlist_query->the_post();

		$img_alig          = get_theme_mod( 'signify_playlist_image_alignment', 'content-align-right' );
		$display_title     = get_theme_mod( 'signify_display_playlist_title', 1 );
		$section_sub_title = get_theme_mod( 'signify_playlist_section_sub_title' );

		$classes[] = 'playlist-section section';
		$classes[] = $img_alig;

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

		$background = get_theme_mod( 'signify_playlist_bg_image' );

		if ( $background ) {
			$classes[] = 'has-background-image';
		}
		?>
		<div id="playlist-section" class=" no-section-heading <?php echo esc_attr( implode( ' ', $classes ) ); ?>">
			<div class="wrapper">
				<div class="section-content-wrapper playlist-content-wrapper layout-one <?php echo esc_attr( $img_alig ); ?>">
					<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
						<div class="hentry-inner">
							<?php $post_thumbnail = signify_post_thumbnail( array(720,720), 'html', 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; ?>
								<?php
								$section_sub_title = apply_filters( 'the_content', $section_sub_title );
								echo wp_kses_post( str_replace( ']]>', ']]&gt;', $section_sub_title ) );
								
								if ( get_theme_mod( 'signify_display_playlist_title', 1 ) ) : ?>
								<header class="entry-header">
									<?php the_title( '<h2 class="entry-title">', '</h2>' ); ?>
								</header><!-- .entry-header -->
								<?php endif; ?>

								<div class="entry-content">
									<?php the_content(); ?>
								</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>
									</footer><!-- .entry-footer -->
								<?php endif; ?>
							</div><!-- .entry-container -->
						</div><!-- .hentry-inner -->
					</article><!-- #post-## -->
				</div><!-- .wrapper -->
			</div><!-- .section-content -->
		</div><!-- #playlist-section -->
	<?php
	endwhile;

	wp_reset_postdata();
endif;
