<?php
/**
 * Displays Banner Section
 *
 * @package FitNote
 */
$is_banner_section = fitnote_get_option('enable_slider_banner_section');
$title_slider_banner_section = fitnote_get_option('title_slider_banner_section');
$enable_banner_overlay = fitnote_get_option('enable_banner_overlay');
$enable_banner_control_icon = fitnote_get_option('enable_banner_control_icon');
$banner_section_cat = fitnote_get_option('banner_section_cat');
$slider_banner_offset = fitnote_get_option('slider_banner_offset');
$number_of_slider_post = fitnote_get_option('number_of_slider_post');
$slider_post_content_alignment = fitnote_get_option('slider_post_content_alignment');
$enable_banner_cat_meta_color = fitnote_get_option('enable_banner_cat_meta_color');
$enable_banner_post_description = fitnote_get_option('enable_banner_post_description');
$enable_banner_slider_author_meta = fitnote_get_option('enable_banner_slider_author_meta');
$select_banner_slider_author_meta = fitnote_get_option('select_banner_slider_author_meta');
$banner_slider_author_meta_title = fitnote_get_option('banner_slider_author_meta_title');
$enable_banner_slider_date_meta = fitnote_get_option('enable_banner_slider_date_meta');
$select_banner_slider_date = fitnote_get_option('select_banner_slider_date');
$select_banner_slider_date_meta_title = fitnote_get_option('select_banner_slider_date_meta_title');
$select_banner_slider_date_format = fitnote_get_option('select_banner_slider_date_format');
$enable_banner_slider_category_meta = fitnote_get_option('enable_banner_slider_category_meta');
$banner_slider_category_label = fitnote_get_option('banner_slider_category_label');
$select_banner_slider_category_color = fitnote_get_option('select_banner_slider_category_color');
$select_banner_slider_number_of_category = fitnote_get_option('select_banner_slider_number_of_category');
$banner_overlay_class = '';
if ($enable_banner_overlay) {
    $banner_overlay_class = 'slider-banner-has-overlay';
}
if ($is_banner_section) :
    ?>
    <section class="wpi-section wpi-slider-banner <?php echo $banner_overlay_class; ?>">

        <header class="section-header default-section-header">
            <div class="wrapper">
                <div class="has-header-controls">
                    <?php if (!empty($title_slider_banner_section)) { ?>
                        <h2 class="section-title">
                            <?php echo esc_html($title_slider_banner_section); ?>
                            <?php fitnote_the_theme_svg('curvy-arrow-down'); ?>
                        </h2>
                    <?php } ?>
                    <?php if ($enable_banner_control_icon) { ?>
                        <div class="section-header-controls">
                            <div class="banner-slider-control banner-slider-prev">
                                <?php fitnote_the_theme_svg('chevron-left'); ?>
                            </div>
                            <div class="banner-slider-control banner-slider-next">
                                <?php fitnote_the_theme_svg('chevron-right'); ?>
                            </div>
                        </div>
                    <?php } ?>
                </div>
            </div>
        </header>

        <div class="wrapper">


            <?php
            if ($slider_banner_offset) {
                $slider_banner_post_offset = $slider_banner_offset;
            } else {
                $slider_banner_post_offset = '';
            }
            $post_args = array(
                'post_type' => 'post',
                'posts_per_page' => absint($number_of_slider_post),
                'post_status' => 'publish',
                'no_found_rows' => 1,
                'offset' => $slider_banner_post_offset,
                'ignore_sticky_posts' => 1,
            );
            // Check for category.
            if (!empty($banner_section_cat)) :
                $post_args['tax_query'] = array(
                    array(
                        'taxonomy' => 'category',
                        'field' => 'term_id',
                        'terms' => $banner_section_cat,
                    ),
                );
            endif;

            $banner_post_query = new WP_Query($post_args);
            if ($banner_post_query->have_posts()): ?>
                <div class="swiper site-banner-hero">
                    <div class="swiper-wrapper">
                        <?php
                        $delay = 100; // Initialize delay
                        while ($banner_post_query->have_posts()): $banner_post_query->the_post(); ?>
                            <div class="swiper-slide swiper-hero-slide <?php echo esc_attr($slider_post_content_alignment); ?>">
                                <article id="popular-post-<?php the_ID(); ?>" <?php post_class('wpi-post wpi-post-default'); ?>  data-aos="fade-up" data-aos-delay="<?php echo esc_attr($delay); ?>">
                                <?php if (has_post_thumbnail()) : ?>
                                    <div class="swiper-slide-image hero-slide-image">

                                        <?php
                                        the_post_thumbnail('large', array(
                                            'alt' => the_title_attribute(array(
                                                'echo' => false,
                                            )),
                                        ));
                                        ?>
                                    </div>
                                <?php endif; ?>
                                <div class="site-banner-description">
                                    <header class="entry-header">
                                        <?php
                                        if ($enable_banner_slider_category_meta) {
                                            fitnote_post_category($select_banner_slider_category_color, $banner_slider_category_label, $select_banner_slider_number_of_category);
                                        }
                                        ?>
                                        <?php the_title('<h2 class="entry-title entry-title-small limit-line-3"><a href="' . esc_url(get_permalink()) . '" rel="bookmark">', '</a></h2>'); ?>
                                    </header>
                                    <div class="entry-meta-wrapper">
                                        <?php
                                        if ($enable_banner_slider_date_meta) {
                                            fitnote_posted_on($select_banner_slider_date_format, $select_banner_slider_date_meta_title, $select_banner_slider_date);
                                        }
                                        ?>
                                        <?php
                                        if ($enable_banner_slider_date_meta && $enable_banner_slider_author_meta) { ?>
                                            <div class="entry-meta-separator"></div>
                                        <?php } ?>
                                        <?php
                                        if ($enable_banner_slider_author_meta) {
                                            fitnote_posted_by($select_banner_slider_author_meta, $banner_slider_author_meta_title);
                                        }
                                        ?>
                                    </div>
                                    <?php
                                    if ($enable_banner_post_description && has_excerpt()): ?>
                                        <div class="entry-summary">
                                            <?php the_excerpt(); ?>
                                        </div>
                                    <?php elseif ($enable_banner_post_description): ?>
                                        <div class="entry-summary">
                                            <?php echo esc_html(wp_trim_words(get_the_content(), 25, '...')); ?>
                                        </div>
                                    <?php endif; ?>

                                </div>
                                </article>
                            </div>
                        <?php
                            $delay += 100; // Increment delay for next post
                        endwhile;
                        wp_reset_postdata();
                        ?>
                    </div>
                </div>
            <?php endif; ?>
        </div>
    </section>
<?php endif;