<?php
/**
 * Template part for displaying services section
 *
 * @package Food Blogger Hub
 * @subpackage food_blogger_hub
 */
?>

<?php 
$food_blogger_hub_latest_posts = get_theme_mod('food_blogger_hub_latest_posts_sec', '1');

if ($food_blogger_hub_latest_posts == '1') : 
?>
<section id="latest-section" class="second-main-box py-5">
  <div class="container">

    <?php if ($food_blogger_hub_section_title = get_theme_mod('food_blogger_hub_section_title')) : ?>
      <h2 class="text-center mb-3 text-capitalize"><?php echo esc_html($food_blogger_hub_section_title); ?></h2>
    <?php endif; ?>
    <?php if ($food_blogger_hub_small_title = get_theme_mod('food_blogger_hub_small_title')) : ?>
      <p class="small-title text-center mb-4"><?php echo esc_html($food_blogger_hub_small_title); ?></p>
    <?php endif; ?>

    <div class="row">
        <div class="col-lg-3 col-md-3 post-one mb-4">
            <?php
              $post_id = get_theme_mod('food_blogger_hub_post_first');
              if ($post_id && $post_id !== 'page-none-selected') :
                $post = get_post($post_id);
                if ($post) : setup_postdata($post);
            ?>
                  <div class="row">
                    <div class="col-lg-12">
                      <?php if (has_post_thumbnail()) : ?>
                        <div class="thumbnail">
                          <?php the_post_thumbnail('full'); ?>
                        </div>
                      <?php else : ?>
                        <div class="latest-post-color first"></div>
                      <?php endif; ?>
                      <div class="inner-box-image">
                        <div class="inner-box text-start">
                            <div class="post-meta my-2">
                              <span class="service-cat">
                                <i class="fas fa-tag me-2"></i>
                                <?php
                                $categories = get_the_category();
                                if (!empty($categories)) {
                                    echo esc_html($categories[0]->name);
                                }
                                ?>
                              </span>
                            </div>
                            <h3 class="mb-3"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                            <div class="postbox-info">
                                <?php 
                                $food_blogger_hub_blog_archive_ordering = get_theme_mod('blog_meta_order', array('author', 'date'));
                                $food_blogger_hub_output = '';

                                foreach ($food_blogger_hub_blog_archive_ordering as $food_blogger_hub_blog_data_order) : 
                                    if ('author' === $food_blogger_hub_blog_data_order) :
                                        $food_blogger_hub_output .= 'By ' . get_the_author();
                                    elseif ('date' === $food_blogger_hub_blog_data_order) :
                                        $food_blogger_hub_output .= ' - ' . get_the_date('j F, Y');
                                    endif;
                                endforeach; 

                                echo '<span class="entry-meta">' . $food_blogger_hub_output . '</span>';
                                ?>
                            </div>
                        </div>
                      </div>
                    </div>
                  </div>
            <?php
                endif;
                wp_reset_postdata();
              else :
                echo '<div class="no-postfound">' . __('No post selected', 'food-blogger-hub') . '</div>';
              endif;
            ?>
        </div>
        <div class="col-lg-3 col-md-3 post-two mb-4">
            <?php
            $post_id = get_theme_mod('food_blogger_hub_post_second');
            $food_blogger_hub_youtube_url = get_theme_mod('food_blogger_hub_youtube_url', '');
            if ($post_id && $post_id !== 'page-none-selected') :
              $post = get_post($post_id);
              if ($post) : setup_postdata($post);
            ?>
                <div class="row">
              <div class="col-lg-12">
                <?php if (has_post_thumbnail()) : ?>
                  <div class="thumbnail position-relative">
                    <?php the_post_thumbnail('full'); ?>
                    <?php if ($food_blogger_hub_youtube_url) : ?>
                      <a href="<?php echo esc_url($food_blogger_hub_youtube_url); ?>" class="youtube-icon-overlay" target="_blank">
                        <i class="fas fa-play"></i>
                      </a>
                    <?php endif; ?>
                  </div>
                <?php else : ?>
                  <div class="latest-post-color second">
                    <a href="<?php echo esc_url($food_blogger_hub_youtube_url); ?>" class="youtube-icon-overlay" target="_blank">
                      <i class="fas fa-play"></i>
                    </a>
                  </div>
                <?php endif; ?>
              </div>
            </div>
            <?php
              endif;
              wp_reset_postdata();
            else :
              echo '<div class="no-postfound">' . __('No post selected', 'food-blogger-hub') . '</div>';
            endif;
            ?>
        </div>
        <div class="col-lg-3 col-md-3 post-third mb-4">
            <?php
              $post_id = get_theme_mod('food_blogger_hub_post_third');
              if ($post_id && $post_id !== 'page-none-selected') :
                $post = get_post($post_id);
                if ($post) : setup_postdata($post);
            ?>
                  <div class="row">
                    <div class="col-lg-12">
                      <?php if (has_post_thumbnail()) : ?>
                        <div class="thumbnail">
                          <?php the_post_thumbnail('full'); ?>
                        </div>
                      <?php else : ?>
                        <div class="latest-post-color third"></div>
                      <?php endif; ?>
                      <div class="inner-box-image">
                        <div class="inner-box">
                            <div class="post-meta my-2">
                                <span class="service-cat">
                                  <i class="fas fa-tag me-2"></i>
                                  <?php
                                  $categories = get_the_category();
                                  if (!empty($categories)) {
                                      echo esc_html($categories[0]->name);
                                  }
                                  ?>
                                </span>
                            </div>
                            <h3 class="mb-3"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                            <div class="postbox-info">
                                <?php 
                                $food_blogger_hub_blog_archive_ordering = get_theme_mod('blog_meta_order', array('author', 'date'));
                                $food_blogger_hub_output = '';

                                foreach ($food_blogger_hub_blog_archive_ordering as $food_blogger_hub_blog_data_order) : 
                                    if ('author' === $food_blogger_hub_blog_data_order) :
                                        $food_blogger_hub_output .= 'By ' . get_the_author();
                                    elseif ('date' === $food_blogger_hub_blog_data_order) :
                                        $food_blogger_hub_output .= ' - ' . get_the_date('j F, Y');
                                    endif;
                                endforeach; 

                                echo '<span class="entry-meta">' . $food_blogger_hub_output . '</span>';
                                ?>
                            </div>
                        </div>
                      </div>
                    </div>
                  </div>
            <?php
                endif;
                wp_reset_postdata();
              else :
                echo '<div class="no-postfound">' . __('No post selected', 'food-blogger-hub') . '</div>';
              endif;
            ?>
        </div>
        <div class="col-lg-3 col-md-3 post-fourth mb-4">
          <?php
          $post_id = get_theme_mod('food_blogger_hub_post_fourth');
          if ($post_id && $post_id !== 'page-none-selected') :
              $post = get_post($post_id);
              if ($post) : setup_postdata($post);
          ?>
              <div class="thumbnail-container">
                  <?php if (has_post_thumbnail()) : ?>
                    <div class="thumbnail">
                      <?php the_post_thumbnail('full'); ?>
                    </div>
                  <?php else : ?>
                    <div class="latest-post-color fourth"></div>
                  <?php endif; ?>
                  <div class="inner-box-four">
                      <div class="post-meta my-2">
                        <span class="service-cat">
                          <i class="fas fa-tag me-2"></i>
                          <?php
                          $categories = get_the_category();
                          if (!empty($categories)) {
                              echo esc_html($categories[0]->name);
                          }
                          ?>
                        </span>
                      </div>
                      <h3 class="mb-3"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                      <div class="postbox-info">
                          <?php 
                          $food_blogger_hub_blog_archive_ordering = get_theme_mod('blog_meta_order', array('author', 'date'));
                          $food_blogger_hub_output = '';

                          foreach ($food_blogger_hub_blog_archive_ordering as $food_blogger_hub_blog_data_order) : 
                              if ('author' === $food_blogger_hub_blog_data_order) :
                                  $food_blogger_hub_output .= 'By ' . get_the_author();
                              elseif ('date' === $food_blogger_hub_blog_data_order) :
                                  $food_blogger_hub_output .= ' - ' . get_the_date('j F, Y');
                              endif;
                          endforeach; 

                          echo '<span class="entry-meta">' . $food_blogger_hub_output . '</span>';
                          ?>
                      </div>
                  </div>
              </div>
          <?php
              endif;
              wp_reset_postdata();
          else :
              echo '<div class="no-postfound">' . __('No post selected', 'food-blogger-hub') . '</div>';
          endif;
          ?>
        </div>
    </div>
  </div>
</section>
<?php endif; ?>