<?php
/**
 * The default template to display the content
 *
 * Used for index/archive/search.
 *
 * @package TOURIMO
 * @since TOURIMO 1.0
 */

$tourimo_template_args = get_query_var( 'tourimo_template_args' );
$tourimo_columns = 1;
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
	}
}
$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 );
?>
<article id="post-<?php the_ID(); ?>" data-post-id="<?php the_ID(); ?>"
	<?php
	post_class( 'post_item post_item_container post_layout_excerpt 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_size' => tourimo_get_thumb_size( strpos( tourimo_get_theme_option( 'body_style' ), 'full' ) !== false
								? 'full'
								: ( $tourimo_expanded 
									? 'huge' 
									: 'big' 
									)
								),
		)
	);

	// 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 ||  $tourimo_show_meta ) {
		?>
		<div class="post_header entry-header">
			<?php
			// Post title
			if ( $tourimo_show_title && apply_filters( 'tourimo_filter_show_blog_title', true, 'excerpt' ) ) {
				do_action( 'tourimo_action_before_post_title' );
				if ( empty( $tourimo_template_args['no_links'] ) ) {
					the_title( sprintf( '<h3 class="post_title entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h3>' );
				} else {
					the_title( '<h3 class="post_title entry-title">', '</h3>' );
				}
				do_action( 'tourimo_action_after_post_title' );
			}
			// Post meta
			if ( apply_filters( 'tourimo_filter_show_blog_meta', $tourimo_show_meta, $tourimo_components, 'excerpt' ) ) {
				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,
							), 'excerpt', 1
						)
					);
					do_action( 'tourimo_action_after_post_meta' );
				}
			}
			?>
		</div><!-- .post_header -->
		<?php
	}

	// Post content
	if ( apply_filters( 'tourimo_filter_show_blog_excerpt', empty( $tourimo_template_args['hide_excerpt'] ) && tourimo_get_theme_option( 'excerpt_length' ) > 0, 'excerpt' ) ) {
		?>
		<div class="post_content entry-content">
			<?php
			if ( tourimo_get_theme_option( 'blog_content' ) == 'fullpost' ) {
				// Post content area
				?>
				<div class="post_content_inner">
					<?php
					do_action( 'tourimo_action_before_full_post_content' );
					the_content( '' );
					do_action( 'tourimo_action_after_full_post_content' );
					?>
				</div>
				<?php
				// Inner pages
				wp_link_pages(
					array(
						'before'      => '<div class="page_links"><span class="page_links_title">' . esc_html__( 'Pages:', 'tourimo' ) . '</span>',
						'after'       => '</div>',
						'link_before' => '<span>',
						'link_after'  => '</span>',
						'pagelink'    => '<span class="screen-reader-text">' . esc_html__( 'Page', 'tourimo' ) . ' </span>%',
						'separator'   => '<span class="screen-reader-text">, </span>',
					)
				);
			} else {
				// Post content area
				tourimo_show_post_content( $tourimo_template_args, '<div class="post_content_inner">', '</div>' );
			}
			?>
		</div><!-- .entry-content -->
		<?php
	}
	?>
</article>
<?php

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