<?php
$enable_dual_cat_section = sportsx_get_option('enable_dual_cat_section');
$dual_category_post_title_1 = sportsx_get_option('dual_category_post_title_1');
$dual_category_post_category = sportsx_get_option('dual_category_post_category');

$dual_category_post_title_2 = sportsx_get_option('dual_category_post_title_2');
$dual_category_post_category_2 = sportsx_get_option('dual_category_post_category_2');

$enable_dual_cat_author_meta = sportsx_get_option('enable_dual_cat_author_meta');
$select_dual_cat_author_meta = sportsx_get_option('select_dual_cat_author_meta');
$dual_cat_author_meta_title = sportsx_get_option('dual_cat_author_meta_title');

$enable_dual_cat_date_meta = sportsx_get_option('enable_dual_cat_date_meta');
$select_dual_cat_date = sportsx_get_option('select_dual_cat_date');
$select_dual_cat_date_meta_title = sportsx_get_option('select_dual_cat_date_meta_title');
$select_dual_cat_date_format = sportsx_get_option('select_dual_cat_date_format');

$enable_dual_cat_category_meta = sportsx_get_option('enable_dual_cat_category_meta');
$dual_cat_category_label = sportsx_get_option('dual_cat_category_label');
$select_dual_cat_category_color = sportsx_get_option('select_dual_cat_category_color');
$select_dual_cat_number_of_category = sportsx_get_option('select_dual_cat_number_of_category');
if (empty($enable_dual_cat_section)) {
    return;
}
?>
<section class="wpi-section theme-dual-showcase">
  <div class="wrapper">
    <div class="row-group">
      <div class="column column-lg-6 border-lg-r">
        <?php if ($dual_category_post_title_1) { ?>
          <header class="wpi-section-header">
            <h2 class="section-header-title"><?php echo esc_html($dual_category_post_title_1); ?></h2>
          </header>
        <?php } ?>
          <div class="dual-showcase-content">

            <?php
            $dual_category_args_1 = array(
                'post_type' => 'post',
                'posts_per_page' => 4,
                'post_status' => 'publish',
                'no_found_rows' => 1,
                'ignore_sticky_posts' => 1,
            );
            // Check for category.
            if (!empty($dual_category_post_category)) :
                $dual_category_args_1['tax_query'] = array(
                    array(
                        'taxonomy' => 'category',
                        'field' => 'term_id',
                        'terms' => $dual_category_post_category,
                    ),
                );
            endif;
            $count = 1;
            $dual_category_post_1 = new WP_Query($dual_category_args_1);
            if ($dual_category_post_1->have_posts()) :
                while ($dual_category_post_1->have_posts()) :
                    $dual_category_post_1->the_post(); ?>
                    <?php if ($count == 1) { ?>
                      <article id="dual-category-block-<?php the_ID(); ?>">
                        <?php if (has_post_thumbnail()) : ?>
                            <div class="entry-image entry-image-big 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_dual_cat_category_meta) {
                                sportsx_post_category($select_dual_cat_category_color, $dual_cat_category_label, $select_dual_cat_number_of_category);
                            }
                            ?>
                            <h3 class="entry-title entry-title-big">
                                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                            </h3>
                            <div class="entry-meta-wrapper">

                                <?php
                                if ($enable_dual_cat_date_meta) {
                                    sportsx_posted_on($select_dual_cat_date_format, $select_dual_cat_date_meta_title, $select_dual_cat_date);
                                }
                                ?>

                                <?php
                                if ($enable_dual_cat_author_meta) {
                                    sportsx_posted_by($select_dual_cat_author_meta, $dual_cat_author_meta_title);
                                }
                                ?>

                            </div>
                        </div>
                      </article>
                      <div class="article-bottom-border">
                    <?php $count++; } else  { ?>
                        <article id="dual-category-block-<?php the_ID(); ?>" class="wpi-post wpi-post-list">
                          <?php if (has_post_thumbnail()) : ?>
                              <div class="entry-image entry-image-thumbnail 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_dual_cat_category_meta) {
                                  sportsx_post_category($select_dual_cat_category_color, $dual_cat_category_label, $select_dual_cat_number_of_category);
                              }
                              ?>
                              <h3 class="entry-title entry-title-small">
                                  <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                              </h3>
                              <div class="entry-meta-wrapper">

                                  <?php
                                  if ($enable_dual_cat_date_meta) {
                                      sportsx_posted_on($select_dual_cat_date_format, $select_dual_cat_date_meta_title, $select_dual_cat_date);
                                  }
                                  ?>

                                  <?php
                                  if ($enable_dual_cat_author_meta) {
                                      sportsx_posted_by($select_dual_cat_author_meta, $dual_cat_author_meta_title);
                                  }
                                  ?>

                              </div>
                          </div>
                        </article>

                        <?php if ($dual_category_post_1->current_post + 1 == $dual_category_post_1->post_count) { ?>
                            </div>
                          </div>
                        <?php } ?>
                    <?php } ?>
                  <?php
                  endwhile;
                wp_reset_postdata();
              endif; ?>
      </div>

      <div class="column column-lg-6">
        <?php if ($dual_category_post_title_2) { ?>
          <header class="wpi-section-header">
            <h2 class="section-header-title"><?php echo esc_html($dual_category_post_title_2); ?></h2>
          </header>
        <?php } ?>
          <div class="dual-showcase-content">

            <?php
            $dual_category_args_2 = array(
                'post_type' => 'post',
                'posts_per_page' => 4,
                'post_status' => 'publish',
                'no_found_rows' => 1,
                'ignore_sticky_posts' => 1,
            );
            // Check for category.
            if (!empty($dual_category_post_category_2)) :
                $dual_category_args_2['tax_query'] = array(
                    array(
                        'taxonomy' => 'category',
                        'field' => 'term_id',
                        'terms' => $dual_category_post_category_2,
                    ),
                );
            endif;
            $count = 1;
            $dual_category_post_2 = new WP_Query($dual_category_args_2);
            if ($dual_category_post_2->have_posts()) :
                while ($dual_category_post_2->have_posts()) :
                    $dual_category_post_2->the_post(); ?>
                    <?php if ($count == 1) { ?>
                      <article id="dual-category-block-<?php the_ID(); ?>">
                        <?php if (has_post_thumbnail()) : ?>
                            <div class="entry-image entry-image-big 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_dual_cat_category_meta) {
                                sportsx_post_category($select_dual_cat_category_color, $dual_cat_category_label, $select_dual_cat_number_of_category);
                            }
                            ?>
                            <h3 class="entry-title entry-title-big">
                                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                            </h3>
                            <div class="entry-meta-wrapper">

                                <?php
                                if ($enable_dual_cat_date_meta) {
                                    sportsx_posted_on($select_dual_cat_date_format, $select_dual_cat_date_meta_title, $select_dual_cat_date);
                                }
                                ?>

                                <?php
                                if ($enable_dual_cat_author_meta) {
                                    sportsx_posted_by($select_dual_cat_author_meta, $dual_cat_author_meta_title);
                                }
                                ?>

                            </div>
                        </div>
                      </article>
                      <div class="article-bottom-border">
                    <?php $count++; } else  { ?>
                        <article id="dual-category-block-<?php the_ID(); ?>" class="wpi-post wpi-post-list">
                          <?php if (has_post_thumbnail()) : ?>
                              <div class="entry-image entry-image-thumbnail 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_dual_cat_category_meta) {
                                  sportsx_post_category($select_dual_cat_category_color, $dual_cat_category_label, $select_dual_cat_number_of_category);
                              }
                              ?>
                              <h3 class="entry-title entry-title-small">
                                  <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                              </h3>
                              <div class="entry-meta-wrapper">

                                  <?php
                                  if ($enable_dual_cat_date_meta) {
                                      sportsx_posted_on($select_dual_cat_date_format, $select_dual_cat_date_meta_title, $select_dual_cat_date);
                                  }
                                  ?>

                                  <?php
                                  if ($enable_dual_cat_author_meta) {
                                      sportsx_posted_by($select_dual_cat_author_meta, $dual_cat_author_meta_title);
                                  }
                                  ?>

                              </div>
                          </div>
                        </article>

                        <?php if ($dual_category_post_2->current_post + 1 == $dual_category_post_2->post_count) { ?>
                            </div>
                          </div>
                        <?php } ?>
                    <?php } ?>
                  <?php
                  endwhile;
                wp_reset_postdata();
              endif; ?>
      </div>
  </div>
</section>