<?php 
// Check if the service section is enabled in Customizer
$automotive_services_servicesec = get_theme_mod('automotive_services_service_show_hide', true);

if ('1' == $automotive_services_servicesec) : ?>
<section id="service-section">
  <div class="container">
    <div class="row">
      <div class="col-lg-7 col-md-6 align-self-center mb-4">
        <div class="match-heading position-relative">
          <?php 
          $automotive_services_service_about_us = get_theme_mod('automotive_services_service_about_us', 'Best Service');
          if (!empty($automotive_services_service_about_us)) : ?>
            <p class="bold-text m-0 text-capitalize"><?php echo esc_html($automotive_services_service_about_us); ?></p>
          <?php endif; ?>
          <?php 
          $automotive_services_service_sub_heading = get_theme_mod('automotive_services_service_sub_heading');
          if (!empty($automotive_services_service_sub_heading)) : ?>
            <h2 class="about-h2 m-0"><?php echo esc_html($automotive_services_service_sub_heading); ?></h2>
          <?php endif; ?>
        </div>
      </div>
      <div class="col-lg-5 col-md-6 align-self-center mb-4">
        <?php 
        $automotive_services_service_about_us_content = get_theme_mod('automotive_services_service_about_us_content');
        if (!empty($automotive_services_service_about_us_content)) : ?>
          <p class="m-0 serv-content"><?php echo esc_html($automotive_services_service_about_us_content); ?></p>
        <?php endif; ?>
      </div>
    </div>
    
    <div class="row">
      <?php
      $automotive_services_post_category = get_theme_mod('automotive_services_offer_section_category','uncategorized');
      if (!empty($automotive_services_post_category)) :
          $automotive_services_num_posts = absint(get_theme_mod('automotive_services_num_posts', 6));
          $automotive_services_category_id = term_exists($automotive_services_post_category, 'category');
          
          if ($automotive_services_category_id !== 0 && $automotive_services_category_id !== null) :
            $automotive_services_page_query = new WP_Query(array(
              'category_name' => sanitize_text_field($automotive_services_post_category),
              'posts_per_page' => $automotive_services_num_posts,
            ));

            if ($automotive_services_page_query->have_posts()) :
              while ($automotive_services_page_query->have_posts()) : $automotive_services_page_query->the_post();
      ?>
                <div class="col-lg-4 col-md-4 wow fadeInUp" data-wow-delay="0.5s">
                  <div class="serv-box mb-3">
                    <div class="inner-box-image">
                      <?php if (has_post_thumbnail()) : ?>
                        <img src="<?php echo esc_url(get_the_post_thumbnail_url(null, 'full')); ?>" alt="<?php the_title_attribute(); ?>" />
                      <?php else : ?>
                        <div class="serv-color"></div>
                      <?php endif; ?>
                      <div class="post-icon">
                        <?php 
                          $automotive_services_current_icon = get_theme_mod('automotive_services_services_icon' . ($automotive_services_page_query->current_post + 1));
                          if (!empty($automotive_services_current_icon)) : 
                        ?>
                          <div class="icon">
                            <i class="<?php echo esc_attr($automotive_services_current_icon); ?> main-icon"></i>
                          </div>
                        <?php endif; ?>
                      </div>
                    </div>
                    <div class="inner-box text-start pt-3">
                      <h3 class="mb-2 text-capitalize">
                        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                      </h3>
                      <p class="main-serv-content"><?php echo esc_html(wp_trim_words(get_the_content(), 16)); ?></p>
                      <div class="serv-btn mt-2">
                        <a href="<?php the_permalink(); ?>">
                          <?php esc_html_e('Read More', 'automotive-services'); ?>
                        </a>
                      </div>
                    </div>
                  </div>
                </div>
              <?php endwhile; ?>
              <?php wp_reset_postdata(); ?>
            <?php else : ?>
              <div class="no-postfound">
                <?php esc_html_e('No posts found.', 'automotive-services'); ?>
              </div>
            <?php endif; ?>
          <?php endif; ?>
      <?php endif; ?>
    </div>
  </div>
</section>
<?php endif; ?>