<?php
$enable_featured_block = blogaura_get_option('enable_featured_block');
$featured_block_category = blogaura_get_option('featured_block_category');
$enable_featured_block_category_meta = blogaura_get_option('enable_featured_block_category_meta');
$select_featured_block_category_color = blogaura_get_option('select_featured_block_category_color');
$select_featured_block_number_of_category = blogaura_get_option('select_featured_block_number_of_category');
$featured_block_category_label = blogaura_get_option('featured_block_category_label');
$enable_featured_block_author_meta = blogaura_get_option('enable_featured_block_author_meta');
$select_featured_block_author_meta = blogaura_get_option('select_featured_block_author_meta');
$featured_block_author_meta_title = blogaura_get_option('featured_block_author_meta_title');
$enable_featured_block_date_meta = blogaura_get_option('enable_featured_block_date_meta');
$select_featured_block_date = blogaura_get_option('select_featured_block_date');
$select_featured_block_date_meta_title = blogaura_get_option('select_featured_block_date_meta_title');
$select_featured_block_date_format = blogaura_get_option('select_featured_block_date_format');
$post_args = array(
    'post_type' => 'post',
    'posts_per_page' => 8,
    'post_status' => 'publish',
    'orderby' => 'date',
    'order' => 'DESC',
);
if (!empty($featured_block_category)) :
    $post_args['tax_query'][] = array(
        'taxonomy' => 'category',
        'field' => 'term_id',
        'terms' => absint($featured_block_category),
    );
endif;
$featured_block_posts = new WP_Query($post_args);
?>
<?php if ($enable_featured_block) { ?>
    <section class="wpi-section theme-featured-block">
        <div class="wrapper">
            <div class="wpi-section-content">
                <?php
                if ($featured_block_posts->have_posts()) :
                    $delay = 100;
                    while ($featured_block_posts->have_posts()) : $featured_block_posts->the_post();
                        $post_index = $featured_block_posts->current_post; ?>
                        <article id="featured-block-<?php the_ID(); ?>" <?php post_class('wpi-post'); ?>
                                 data-aos="fade-up" data-aos-duration="1000"
                                 data-aos-delay="<?php echo esc_attr($delay); ?>">
                            <?php if (has_post_thumbnail()) : ?>
                                <div class="entry-image entry-image-medium image-hover-effect hover-effect-shine">
                                    <a class="post-thumbnail" href="<?php the_permalink(); ?>"
                                       aria-hidden="true" tabindex="-1">
                                        <?php
                                        the_post_thumbnail(
                                            'medium',
                                            array(
                                                'alt' => the_title_attribute(
                                                    array(
                                                        'echo' => false,
                                                    )
                                                )
                                            )
                                        )
                                        ?>
                                    </a>
                                </div>
                            <?php endif; ?>
                            <div class="entry-details">
                                <?php
                                if ($enable_featured_block_category_meta) {
                                    blogaura_post_category($select_featured_block_category_color, $featured_block_category_label, $select_featured_block_number_of_category);
                                }
                                ?>
                                <h2 class="entry-title entry-title-xsmall limit-line-3"><a
                                            href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                                <div class="entry-meta-wrapper">
                                    <?php
                                    if ($enable_featured_block_date_meta) {
                                        blogaura_posted_on($select_featured_block_date_format, $select_featured_block_date_meta_title, $select_featured_block_date);
                                    }
                                    ?>
                                    <?php
                                    if ($enable_featured_block_date_meta && $enable_featured_block_author_meta) { ?>
                                        <div class="entry-meta-separator"></div>
                                    <?php } ?>
                                    <?php
                                    if ($enable_featured_block_author_meta) {
                                        blogaura_posted_by($select_featured_block_author_meta, $featured_block_author_meta_title);
                                    }
                                    ?>
                                </div>
                            </div>
                        </article>
                        <?php
                        $delay += 100;
                    endwhile; ?>
                    <?php wp_reset_postdata(); // Reset post data
                    ?>
                <?php endif; ?>
            </div>
        </div>
    </section>
<?php } ?>