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

$tourimo_template_args = get_query_var( 'tourimo_template_args' );

$tourimo_columns       = 1;

$tourimo_expanded      = ! tourimo_sidebar_present() && tourimo_get_theme_option( 'expand_content' ) == 'expand';

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

if ( is_array( $tourimo_template_args ) ) {
	$tourimo_columns    = empty( $tourimo_template_args['columns'] ) ? 1 : max( 1, $tourimo_template_args['columns'] );
	$tourimo_blog_style = array( $tourimo_template_args['type'], $tourimo_columns );
	if ( ! empty( $tourimo_template_args['slider'] ) ) {
		?><div class="slider-slide swiper-slide">
		<?php
	} elseif ( $tourimo_columns > 1 ) {
		?>
		<div class="column-1_<?php echo esc_attr( $tourimo_columns ); ?>">
		<?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( $tourimo_post_format ) );
	tourimo_add_blog_animation( $tourimo_template_args );
	?>
>
	<?php

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

	// Featured image
	$tourimo_hover      = ! empty( $tourimo_template_args['hover'] ) && ! tourimo_is_inherit( $tourimo_template_args['hover'] )
							? $tourimo_template_args['hover']
							: tourimo_get_theme_option( 'image_hover' );
	$tourimo_components = ! empty( $tourimo_template_args['meta_parts'] )
							? ( is_array( $tourimo_template_args['meta_parts'] )
								? $tourimo_template_args['meta_parts']
								: array_map( 'trim', explode( ',', $tourimo_template_args['meta_parts'] ) )
								)
							: tourimo_array_get_keys_by_value( tourimo_get_theme_option( 'meta_parts' ) );
	tourimo_show_post_featured(
		array(
			'no_links'   => ! empty( $tourimo_template_args['no_links'] ),
			'hover'      => $tourimo_hover,
			'meta_parts' => $tourimo_components,
			'thumb_bg'   => true,
			'thumb_size' => tourimo_get_thumb_size( 
								in_array( $tourimo_post_format, array( 'gallery', 'audio', 'video' ) )
									? ( strpos( tourimo_get_theme_option( 'body_style' ), 'full' ) !== false
										? 'full'
										: ( $tourimo_expanded 
											? 'big' 
											: 'normal'
											)
										)
									: 'masonry-big'
								)
		)
	);

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

		// Title and post meta
		$tourimo_show_title = get_the_title() != '';
		$tourimo_show_meta  = count( $tourimo_components ) > 0 && ! in_array( $tourimo_hover, array( 'border', 'pull', 'slide', 'fade', 'info' ) );
		if ( $tourimo_show_title ) {
			?>
			<div class="post_header entry-header">
				<?php
				// Categories
				if ( apply_filters( 'tourimo_filter_show_blog_categories', $tourimo_show_meta && in_array( 'categories', $tourimo_components ), array( 'categories' ), 'band' ) ) {
					do_action( 'tourimo_action_before_post_category' );
					?>
					<div class="post_category">
						<?php
						tourimo_show_post_meta( apply_filters(
															'tourimo_filter_post_meta_args',
															array(
																'components' => 'categories',
																'seo'        => false,
																'echo'       => true,
																),
															'hover_' . $tourimo_hover, 1
															)
											);
						?>
					</div>
					<?php
					$tourimo_components = tourimo_array_delete_by_value( $tourimo_components, 'categories' );
					do_action( 'tourimo_action_after_post_category' );
				}
				// Post title
				if ( apply_filters( 'tourimo_filter_show_blog_title', true, 'band' ) ) {
					do_action( 'tourimo_action_before_post_title' );
					if ( empty( $tourimo_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( 'tourimo_action_after_post_title' );
				}
				?>
			</div><!-- .post_header -->
			<?php
		}

		// Post content
		if ( ! isset( $tourimo_template_args['excerpt_length'] ) && ! in_array( $tourimo_post_format, array( 'gallery', 'audio', 'video' ) ) ) {
			$tourimo_template_args['excerpt_length'] = 30;
		}
		if ( apply_filters( 'tourimo_filter_show_blog_excerpt', empty( $tourimo_template_args['hide_excerpt'] ) && tourimo_get_theme_option( 'excerpt_length' ) > 0, 'band' ) ) {
			?>
			<div class="post_content entry-content">
				<?php
				// Post content area
				tourimo_show_post_content( $tourimo_template_args, '<div class="post_content_inner">', '</div>' );
				?>
			</div><!-- .entry-content -->
			<?php
		}
		// Post meta
		if ( apply_filters( 'tourimo_filter_show_blog_meta', $tourimo_show_meta, $tourimo_components, 'band' ) ) {
			if ( count( $tourimo_components ) > 0 ) {
				do_action( 'tourimo_action_before_post_meta' );
				tourimo_show_post_meta(
					apply_filters(
						'tourimo_filter_post_meta_args', array(
							'components' => join( ',', $tourimo_components ),
							'seo'        => false,
							'echo'       => true,
						), 'band', 1
					)
				);
				do_action( 'tourimo_action_after_post_meta' );
			}
		}
		// More button
		if ( apply_filters( 'tourimo_filter_show_blog_readmore', ! $tourimo_show_title, 'band' ) ) {
			if ( empty( $tourimo_template_args['no_links'] ) ) {
				do_action( 'tourimo_action_before_post_readmore' );
				tourimo_show_post_more_link( $tourimo_template_args, '<p>', '</p>' );
				do_action( 'tourimo_action_after_post_readmore' );
			}
		}
		?>
	</div>
</article>
<?php

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