<?php if (!defined('FW')) die( 'Forbidden' ); 

$mobile_classes ='';

$mobile_classes .=  $atts['hide_on_desktop'] == 'true' ? 'hidden-md hidden-lg ' : '';
$mobile_classes .=  $atts['hide_on_mobile'] == 'true' ? 'hidden-xs hidden-sm' : '';

$posts_number = $atts['posts_number'] ? $atts['posts_number'] : -1;
$columns_number = $atts['columns_number'] ? $atts['columns_number'] : 3;
$view_all = $atts['view_all'];

// WOW Animation
$wow_classes = '';
$wow_data = '';

if ( isset($atts['animation_on_scroll']) && $atts['animation_on_scroll']['animation_enable'] == 'yes') {
	$wow_classes = 'is-wow ' . $atts['animation_on_scroll']['yes']['animation_type'];

	if ( isset($atts['animation_on_scroll']['yes']['animation_delay']) ) {
		$wow_data =  'data-wow-delay="' . ($atts['animation_on_scroll']['yes']['animation_delay'] / 1000) . 's"';
	}
	
}
?>

<div class="ShortcodeBlog <?php echo esc_attr($mobile_classes); ?> <?php echo esc_attr($wow_classes); ?>" id="shortcode-<?php echo esc_attr($atts['id']); ?>" <?php echo wp_kses_post($wow_data); ?>>

<?php 
$args = array(
	'post_type' => 'post',
	'max_num_pages' => 1,
	'posts_per_page' => $posts_number,
	'post_status' => 'publish'
);

$posts_query = new WP_Query($args);

?>

	<div class="SimplifiedPosts text-center pos-r is-matchheight-group posts-cols-<?php echo esc_attr($columns_number); ?> mb-40">
							
		<?php if ($posts_query->have_posts()) : while ($posts_query->have_posts()) : $posts_query->the_post(); ?>

			<?php if ( has_post_thumbnail() ) : ?>
			<div class="simplified-post-wrapper mb-40">
				<a href="<?php echo esc_url(get_permalink($posts_query->ID)); ?>">
					<?php $thumb_id = get_post_thumbnail_id($posts_query->ID); ?>
					<div class="SimplifiedImage">
						<?php echo wp_get_attachment_image( $thumb_id, 'odrin_landscape_large' ); ?>
					</div>
			<?php else : ?>
			<div class="simplified-post-wrapper mt-80 mb-40">
				<a href="<?php echo esc_url(get_permalink($posts_query->ID)); ?>">
			<?php endif; ?>
					<div class="simplified-post-meta">
						<div class="ElementHeading">
							<h4 class="element-title"><?php echo get_the_title($posts_query->ID) ?></h4>
						</div> <!-- end ElementHeading -->
						<div class="simplified-post-date"><span><?php echo esc_html(get_the_date(get_option('date_format'))); ?></span></div>
						<div class="simplified-post-read-more text-right"><span class="special-subtitle-type-2"><?php echo esc_html__('Read More', 'odrin'); ?></span></div>
					</div>
				</a>
			</div> <!-- end simplified-post-meta -->

		<?php endwhile; ?>

		<?php
		wp_reset_postdata();
		endif; 
	?>

	</div> <!-- end SimplifiedPosts -->

	<?php if ( $view_all['view_all'] == 'true') : ?>
		<?php $parent_blog_id = odrin_parent_blog_id(); 
		if ( $parent_blog_id ) : ?>
		<div class="blog-show-more special-link text-right">
			<a href="<?php echo esc_url(get_permalink($parent_blog_id)) ;?>"><?php echo wp_kses_post($view_all['true']['label']); ?></a>
		</div>
		<?php else : 
			if ( current_user_can('publish_pages') ) : ?>
			<span class="admin-alert"><?php echo wp_kses_post(__('<strong>Note!</strong> Make sure than you have published one page that uses the Page Template "Blog" in order to display the View All button.', 'odrin')); ?></span>
			<?php endif; ?>
		<?php endif; ?>
	<?php endif; ?>

</div> <!-- end ShortcodeBlog -->