<?php
$enable_featured_block = sportsx_get_option('enable_featured_block');
$featured_block_category = sportsx_get_option('featured_block_category');
$enable_featured_block_category_meta = sportsx_get_option('enable_featured_block_category_meta');
$select_featured_block_category_color = sportsx_get_option('select_featured_block_category_color');
$select_featured_block_number_of_category = sportsx_get_option('select_featured_block_number_of_category');
$featured_block_category_label = sportsx_get_option('featured_block_category_label');
$featured_block_title = sportsx_get_option('featured_block_title');

$enable_featured_block_author_meta = sportsx_get_option('enable_featured_block_author_meta');
$select_featured_block_author_meta = sportsx_get_option('select_featured_block_author_meta');
$featured_block_author_meta_title = sportsx_get_option('featured_block_author_meta_title');

$enable_featured_block_date_meta = sportsx_get_option('enable_featured_block_date_meta');
$select_featured_block_date = sportsx_get_option('select_featured_block_date');
$select_featured_block_date_meta_title = sportsx_get_option('select_featured_block_date_meta_title');
$select_featured_block_date_format = sportsx_get_option('select_featured_block_date_format');

$post_args = array(
  'post_type' => 'post',
  'posts_per_page' => 6,
  '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="row-group">
        <?php 
        if($featured_block_posts->have_posts()) :
          while ($featured_block_posts->have_posts()) : $featured_block_posts->the_post();
          $post_index = $featured_block_posts->current_post;
          if($post_index === 0) : ?>

          <div class="column column-lg-8 column-md-7 border-lg-r">
            <div class="featured-block-left">
              <article id="featured-block-<?php the_ID(); ?>" <?php post_class(''); ?>>
                <div class="entry-details">
                  <?php
                    if ($enable_featured_block_category_meta) {
                        sportsx_post_category($select_featured_block_category_color, $featured_block_category_label, $select_featured_block_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(sportsx_get_archive_excerpt())); ?>
                  </div>

                  <div class="entry-meta-wrapper">
                    <?php
                    if ($enable_featured_block_date_meta) {
                        sportsx_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) {
                        sportsx_posted_by($select_featured_block_author_meta, $featured_block_author_meta_title);
                    }
                    ?>
                  </div>
                  
                </div>
                
                <?php if (has_post_thumbnail()) : ?>
                  <div class="entry-image entry-image-large image-hover-effect hover-effect-shine">
                    <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 endif; ?>
              </article>
            </div>
          </div>

          <div class="column column-lg-4 column-md-5">
            <div class="featured-block-right article-bottom-border">
            <?php if ($featured_block_title) { ?>
              <header class="wpi-section-header">
                <h2 class="section-header-title">
                  <?php echo esc_html($featured_block_title) ?>
                </h2>
              </header>
            <?php } ?>
          
            <?php else : ?>
              <article id="featured-block-<?php the_ID(); ?>" <?php post_class(''); ?>>
                <div class="entry-details">
                  <h2 class="entry-title entry-title-small">
                    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                  </h2>

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

                      <?php
                      if ($enable_featured_block_date_meta) {
                          sportsx_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) {
                          sportsx_posted_by($select_featured_block_author_meta, $featured_block_author_meta_title);
                      }
                      ?>

                  </div>
                  
                </div>

                <?php sportsx_the_theme_svg('arrow-right'); ?>
              </article>
        <?php endif; ?>

        <?php endwhile; ?>
          <?php endif;
        wp_reset_postdata(); // Reset post data ?>
          </div>
        </div>
      </div>
    </div>
  </section>
<?php } 