<?php
/**
 * Template part for displaying the services section
 *
 * @package Farming Store
 * @subpackage Farming Store
 */
?>

<?php 
$farming_store_servicesec = get_theme_mod('farming_store_service_show_hide', true);

if ($farming_store_servicesec == '1') : 
?>
<section id="service-section">
  <div class="container"> 
    <div class="serv-head mb-3">
      <?php if (get_theme_mod('farming_store_section_title')) : ?>
        <h2 class="text-capitalize mt-2" id="section-title"><?php echo esc_html(get_theme_mod('farming_store_section_title')); ?></h2>
      <?php endif; ?> 
    </div>
    <div class="owl-carousel owl-theme">
      <?php
      $farming_store_post_category = get_theme_mod('farming_store_offer_section_category');
      if ($farming_store_post_category) :
        $farming_store_category_id = term_exists($farming_store_post_category, 'category');
        if ($farming_store_category_id !== 0 && $farming_store_category_id !== null) :
          $farming_store_posts_to_show = get_theme_mod('farming_store_posts_to_show', 2);
          $farming_store_page_query = new WP_Query(array(
            'category_name' => esc_attr($farming_store_post_category),
            'posts_per_page' => $farming_store_posts_to_show,
          ));

          $farming_store_post_count = 0;
          if ($farming_store_page_query->have_posts()) :
            while ($farming_store_page_query->have_posts()) : $farming_store_page_query->the_post(); 
              $farming_store_post_count++;
          ?>
              <div class="item">
                <div class="serv-box">
                  <div class="row">
                    <div class="col-lg-5 col-md-12 align-self-center pe-lg-0">
                      <div class="inner-box-image">
                        <?php if (has_post_thumbnail()) : ?>
                          <img src="<?php echo esc_url(get_the_post_thumbnail_url(null, 'full')); ?>" />
                        <?php else : ?>
                          <img class="serv-color" src="<?php echo esc_url(get_template_directory_uri() . '/assets/images/sliderimage.png'); ?>" alt="Default Image" />
                        <?php endif; ?>
                      </div>
                    </div>
                    <div class="col-lg-7 col-md-12 align-self-center ps-lg-0">
                      <div class="inner-box text-start p-lg-3 px-md-3 py-md-3 p-3">
                        <div class="main-serv-date">
                          <a href="<?php echo esc_url(get_day_link(get_the_date('Y'), get_the_date('m'), get_the_date('d'))); ?>" class="entry-date">
                            <i class="far fa-calendar-alt pe-lg-2 pe-1"></i> <?php echo esc_html(get_the_date('d F Y')); ?>
                          </a>
                          <hr>
                        </div>
                        <div class="user-comm">
                          <a class="me-md-4 me-3" href="<?php echo esc_url(get_author_posts_url(get_the_author_meta('ID'))); ?>">
                            <i class="far fa-user pe-2"></i><?php the_author(); ?>
                          </a>
                          <span class="entry-comments">
                            <a href="<?php comments_link(); ?>" class="ms-2">
                              <i class="far fa-comments pe-2"></i><?php comments_number( __('0 Comments', 'farming-store'), __('1 Comment', 'farming-store'), __('% Comments', 'farming-store') ); ?>
                            </a>
                          </span>
                        </div>
                        <h3 class="mb-2 text-capitalize"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                        <p class="main-serv-content my-2"><?php echo wp_trim_words( get_the_content(),15 );?></p>
                        <div class="more-details">
                          <a href="<?php the_permalink(); ?>"><?php esc_html_e('Read More', 'farming-store'); ?><i class="fas fa-arrow-right ms-2"></i></a>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            <?php endwhile; ?>
            <?php wp_reset_postdata(); ?>
          <?php else : ?>
            <div class="no-postfound"></div>
          <?php endif; ?>
        <?php endif; ?>
      <?php endif; ?>
    </div>
  </div>
</section>
<?php endif; ?>