<?php
$enable_main_banner_section = bloglex_get_option('enable_main_banner_section');
$banner_slider_post_category = bloglex_get_option('banner_slider_post_category');

$banner_lists_post_category = bloglex_get_option('banner_lists_post_category');

$enable_main_banner_author_meta = bloglex_get_option('enable_main_banner_author_meta');
$select_main_banner_author_meta = bloglex_get_option('select_main_banner_author_meta');
$main_banner_author_meta_title = bloglex_get_option('main_banner_author_meta_title');

$enable_main_banner_date_meta = bloglex_get_option('enable_main_banner_date_meta');
$select_main_banner_date = bloglex_get_option('select_main_banner_date');
$select_main_banner_date_meta_title = bloglex_get_option('select_main_banner_date_meta_title');
$select_main_banner_date_format = bloglex_get_option('select_main_banner_date_format');

$enable_main_banner_category_meta = bloglex_get_option('enable_main_banner_category_meta');
$main_banner_category_label = bloglex_get_option('main_banner_category_label');
$select_main_banner_category_color = bloglex_get_option('select_main_banner_category_color');
$select_main_banner_number_of_category = bloglex_get_option('select_main_banner_number_of_category');
if (empty($enable_main_banner_section)) {
    return;
}
?>


<section class="wpi-section theme-main-banner">
  <div class="wrapper wrapper-gutter-medium">
    <div class="row-group">
      <div class="column column-lg-12">
        <div class="main-banner-top">
          <div class="main-banner-slider swiper">
            <div class="swiper-wrapper">
                <?php
                // post slider section
                $post_slider_args = array(
                    'post_type' => 'post',
                    'posts_per_page' => 5,
                    'post_status' => 'publish',
                    'no_found_rows' => 1,
                    'ignore_sticky_posts' => 1,
                );
                // Check for category.
                if (!empty($banner_slider_post_category)) :
                    $post_slider_args['tax_query'] = array(
                        array(
                            'taxonomy' => 'category',
                            'field' => 'term_id',
                            'terms' => $banner_slider_post_category,
                        ),
                    );
                endif;
                $slider_posts = new WP_Query($post_slider_args);
                if ($slider_posts->have_posts()) :
                    while ($slider_posts->have_posts()) :
                        $slider_posts->the_post(); ?>
                        <div class="swiper-slide">
                          <article id="main-banner-<?php the_ID(); ?>" class="wpi-post">
                            <?php if (has_post_thumbnail()) : ?>
                                <div class="entry-image">
                                    <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1">
                                        <?php
                                        the_post_thumbnail(
                                            'large',
                                            array(
                                                'alt' => the_title_attribute(
                                                    array(
                                                        'echo' => false,
                                                    )
                                                ),
                                            )
                                        );
                                        ?>
                                    </a>
                                </div>
                            <?php else: ?>
                                <div class="entry-image">
                                    <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1">
                                        <img src="<?php echo esc_url(bloglex_placeholder_image()); ?>" alt="<?php the_title_attribute(); ?>">
                                    </a>
                                </div>
                            <?php endif; ?>

                            <div class="entry-details">
                              <?php
                              if ($enable_main_banner_category_meta) {
                                  bloglex_post_category($select_main_banner_category_color, $main_banner_category_label, $select_main_banner_number_of_category);
                              }
                              ?>
                              <h2 class="entry-title entry-title-large">
                                  <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                              </h2>

                              <div class="entry-content-excerpt">
                                  <?php echo wpautop(wp_kses_post(bloglex_get_archive_excerpt())); ?>
                              </div>

                              <div class="entry-meta-wrapper">

                                  <?php
                                  if ($enable_main_banner_date_meta) {
                                      bloglex_posted_on($select_main_banner_date_format, $select_main_banner_date_meta_title, $select_main_banner_date);
                                  }
                                  ?>

                                  <?php
                                  if ($enable_main_banner_author_meta) {
                                      bloglex_posted_by($select_main_banner_author_meta, $main_banner_author_meta_title);
                                  }
                                  ?>

                              </div>
                            </div>
                          </article>
                        </div>
                    <?php
                    endwhile;
                  wp_reset_postdata();
                endif; ?>
            </div>

            <div class="swiper-pagination"></div>
            <div class="swiper-button-next"></div>
            <div class="swiper-button-prev"></div>
          </div>
        </div>

        <div class="main-banner-bottom">
            <?php
            // post grid bottom section
            $post_list_args = array(
                'post_type' => 'post',
                'posts_per_page' => 4,
                'post_status' => 'publish',
                'no_found_rows' => 1,
                'ignore_sticky_posts' => 1,
            );
            // Check for category.
            if (!empty($banner_lists_post_category)) :
                $post_list_args['tax_query'] = array(
                    array(
                        'taxonomy' => 'category',
                        'field' => 'term_id',
                        'terms' => $banner_lists_post_category,
                    ),
                );
            endif;
            $count = 1;
            $slider_list_posts = new WP_Query($post_list_args);
            if ($slider_list_posts->have_posts()) :
                while ($slider_list_posts->have_posts()) :
                    $slider_list_posts->the_post(); ?>
                    <article id="main-banner-<?php the_ID(); ?>"
                      class="wpi-post post-122 post type-post status-publish format-standard has-post-thumbnail hentry category-editorial category-fashion tag-12 tag-outfit tag-summer tag-wear">
                      <?php if (has_post_thumbnail()) : ?>
                        <div class="entry-image entry-image-medium">
                            <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_main_banner_category_meta) {
                              bloglex_post_category($select_main_banner_category_color, $main_banner_category_label, $select_main_banner_number_of_category);
                          }
                          ?>
                          <h3 class="entry-title entry-title-medium limit-line-2">
                              <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                          </h3>
                          <div class="entry-meta-wrapper">

                              <?php
                              if ($enable_main_banner_date_meta) {
                                  bloglex_posted_on($select_main_banner_date_format, $select_main_banner_date_meta_title, $select_main_banner_date);
                              }
                              ?>

                              <?php
                              if ($enable_main_banner_author_meta) {
                                  bloglex_posted_by($select_main_banner_author_meta, $main_banner_author_meta_title);
                              }
                              ?>

                          </div>
                      </div>
                    </article>
                <?php
                endwhile;
              wp_reset_postdata();
            endif; ?>
        </div>

      </div>
    </div>
  </div>
</section>