<?php
/**
 * 'Band' template to display the content
 *
 * Used for index/archive/search.
 *
 * @package PANTRY
 * @since PANTRY 1.71.0
 */

$pantry_template_args = get_query_var( 'pantry_template_args' );
if ( ! is_array( $pantry_template_args ) ) {
	$pantry_template_args = array(
								'type'    => 'band',
								'columns' => 1
								);
}

$pantry_columns       = 1;

$pantry_expanded      = ! pantry_sidebar_present() && pantry_get_theme_option( 'expand_content' ) == 'expand';

$pantry_post_format   = get_post_format();
$pantry_post_format   = empty( $pantry_post_format ) ? 'standard' : str_replace( 'post-format-', '', $pantry_post_format );

if ( is_array( $pantry_template_args ) ) {
	$pantry_columns    = empty( $pantry_template_args['columns'] ) ? 1 : max( 1, $pantry_template_args['columns'] );
	$pantry_blog_style = array( $pantry_template_args['type'], $pantry_columns );
	if ( ! empty( $pantry_template_args['slider'] ) ) {
		?><div class="slider-slide swiper-slide">
		<?php
	} elseif ( $pantry_columns > 1 ) {
	    $pantry_columns_class = pantry_get_column_class( 1, $pantry_columns, ! empty( $pantry_template_args['columns_tablet']) ? $pantry_template_args['columns_tablet'] : '', ! empty($pantry_template_args['columns_mobile']) ? $pantry_template_args['columns_mobile'] : '' );
				?><div class="<?php echo esc_attr( $pantry_columns_class ); ?>"><?php
	}
}
?>
<article id="post-<?php the_ID(); ?>" data-post-id="<?php the_ID(); ?>"
	<?php
	post_class( 'post_item post_item_container post_layout_band post_format_' . esc_attr( $pantry_post_format ) );
	pantry_add_blog_animation( $pantry_template_args );
	?>
>
	<?php

	// Sticky label
	if ( is_sticky() && ! is_paged() ) {
		?>
		<span class="post_label label_sticky"></span>
		<?php
	}

	// Featured image
	$pantry_hover      = ! empty( $pantry_template_args['hover'] ) && ! pantry_is_inherit( $pantry_template_args['hover'] )
							? $pantry_template_args['hover']
							: pantry_get_theme_option( 'image_hover' );
	$pantry_components = ! empty( $pantry_template_args['meta_parts'] )
							? ( is_array( $pantry_template_args['meta_parts'] )
								? $pantry_template_args['meta_parts']
								: array_map( 'trim', explode( ',', $pantry_template_args['meta_parts'] ) )
								)
							: pantry_array_get_keys_by_value( pantry_get_theme_option( 'meta_parts' ) );
	pantry_show_post_featured( apply_filters( 'pantry_filter_args_featured',
		array(
			'no_links'   => ! empty( $pantry_template_args['no_links'] ),
			'hover'      => $pantry_hover,
			'meta_parts' => $pantry_components,
			'thumb_bg'   => true,
			'thumb_ratio'   => '1:1',
			'thumb_size' => ! empty( $pantry_template_args['thumb_size'] )
								? $pantry_template_args['thumb_size']
								: pantry_get_thumb_size( 
								in_array( $pantry_post_format, array( 'gallery', 'audio', 'video' ) )
									? ( strpos( pantry_get_theme_option( 'body_style' ), 'full' ) !== false
										? 'full'
										: ( $pantry_expanded 
											? 'big' 
											: 'medium-square'
											)
										)
									: 'masonry-big'
								)
		),
		'content-band',
		$pantry_template_args
	) );

	?><div class="post_content_wrap"><?php

		// Title and post meta
		$pantry_show_title = get_the_title() != '';
		$pantry_show_meta  = count( $pantry_components ) > 0 && ! in_array( $pantry_hover, array( 'border', 'pull', 'slide', 'fade', 'info' ) );
		if ( $pantry_show_title ) {
			?>
			<div class="post_header entry-header">
				<?php
				// Categories
				if ( apply_filters( 'pantry_filter_show_blog_categories', $pantry_show_meta && in_array( 'categories', $pantry_components ), array( 'categories' ), 'band' ) ) {
					do_action( 'pantry_action_before_post_category' );
					?>
					<div class="post_category">
						<?php
						pantry_show_post_meta( apply_filters(
															'pantry_filter_post_meta_args',
															array(
																'components' => 'categories',
																'seo'        => false,
																'echo'       => true,
																'cat_sep'    => false,
																),
															'hover_' . $pantry_hover, 1
															)
											);
						?>
					</div>
					<?php
					$pantry_components = pantry_array_delete_by_value( $pantry_components, 'categories' );
					do_action( 'pantry_action_after_post_category' );
				}
				// Post title
				if ( apply_filters( 'pantry_filter_show_blog_title', true, 'band' ) ) {
					do_action( 'pantry_action_before_post_title' );
					if ( empty( $pantry_template_args['no_links'] ) ) {
						the_title( sprintf( '<h4 class="post_title entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h4>' );
					} else {
						the_title( '<h4 class="post_title entry-title">', '</h4>' );
					}
					do_action( 'pantry_action_after_post_title' );
				}
				?>
			</div><!-- .post_header -->
			<?php
		}

		// Post content
		if ( ! isset( $pantry_template_args['excerpt_length'] ) && ! in_array( $pantry_post_format, array( 'gallery', 'audio', 'video' ) ) ) {
			$pantry_template_args['excerpt_length'] = 13;
		}
		if ( apply_filters( 'pantry_filter_show_blog_excerpt', empty( $pantry_template_args['hide_excerpt'] ) && pantry_get_theme_option( 'excerpt_length' ) > 0, 'band' ) ) {
			?>
			<div class="post_content entry-content">
				<?php
				// Post content area
				pantry_show_post_content( $pantry_template_args, '<div class="post_content_inner">', '</div>' );
				?>
			</div><!-- .entry-content -->
			<?php
		}
		// Post meta
		if ( apply_filters( 'pantry_filter_show_blog_meta', $pantry_show_meta, $pantry_components, 'band' ) ) {
			if ( count( $pantry_components ) > 0 ) {
				do_action( 'pantry_action_before_post_meta' );
				pantry_show_post_meta(
					apply_filters(
						'pantry_filter_post_meta_args', array(
							'components' => join( ',', $pantry_components ),
							'seo'        => false,
							'echo'       => true,
						), 'band', 1
					)
				);
				do_action( 'pantry_action_after_post_meta' );
			}
		}
		// More button
		if ( apply_filters( 'pantry_filter_show_blog_readmore', ! $pantry_show_title || ! empty( $pantry_template_args['more_button'] ), 'band' ) ) {
			if ( empty( $pantry_template_args['no_links'] ) ) {
				do_action( 'pantry_action_before_post_readmore' );
				pantry_show_post_more_link( $pantry_template_args, '<div class="more-wrap">', '</div>' );
				do_action( 'pantry_action_after_post_readmore' );
			}
		}
		?>
	</div>
</article>
<?php

if ( is_array( $pantry_template_args ) ) {
	if ( ! empty( $pantry_template_args['slider'] ) || $pantry_columns > 1 ) {
		?>
		</div>
		<?php
	}
}
