<?php
/**
 * Template part for displaying services section
 *
 * @package Business Accountant
 * @subpackage business_accountant
 */
?>

<?php
// Static image URL
$business_accountant_static_image = get_stylesheet_directory_uri() . '/assets/images/header_img.png';
?>

<?php if (get_theme_mod('business_accountant_show_hide_sec', true)) : ?>
  <section id="service-sec" class="my-5">
    <div class="container">
      <div class="text-center">
        <?php
        // Short heading
        $business_accountant_serv_short_heading = get_theme_mod('business_accountant_serv_short_heading', '');
        if ($business_accountant_serv_short_heading) : ?>
          <p class="serv-short text-center d-inline-block text-capitalize"><?php echo esc_html($business_accountant_serv_short_heading); ?></p>
        <?php endif; ?>

        <?php
        // Featured section title
        $business_accountant_featured_section_title = get_theme_mod('business_accountant_featured_section_title', '');
        if ($business_accountant_featured_section_title) : ?>
          <h2 class="text-center mb-lg-5 mb-4 text-capitalize"><?php echo esc_html($business_accountant_featured_section_title); ?></h2>
        <?php endif; ?>
      </div>

      <div id="service-carousel" class="owl-carousel owl-theme">
        <?php
        // Get posts from specified category
        $business_accountant_post_category = get_theme_mod('business_accountant_featured_section_category', '');
        if ($business_accountant_post_category) :
          $business_accountant_page_query = new WP_Query(array(
            'category_name' => esc_html($business_accountant_post_category),
          ));

          if ($business_accountant_page_query->have_posts()) :
            while ($business_accountant_page_query->have_posts()) : $business_accountant_page_query->the_post(); ?>
              <div class="item position-relative mb-4">
                <div class="cat-inner-box">
                  <?php if (has_post_thumbnail()) : ?>
                    <img src="<?php echo esc_url(get_the_post_thumbnail_url(null, 'full')); ?>" alt="<?php echo esc_attr(get_the_title()); ?>" />
                  <?php else : ?>
                    <img src="<?php echo esc_url($business_accountant_static_image); ?>" alt="<?php esc_attr_e('Default Image', 'business-accountant'); ?>">
                  <?php endif; ?>
                  <div class="inner-content">
                    <div class="post-title">
                      <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                      <p class="mb-0"><?php echo wp_trim_words(get_the_content(), 10); ?></p>
                    </div>
                  </div>
                </div>
              </div>
            <?php endwhile;
            wp_reset_postdata();
          endif;
        endif;
        ?>
      </div>
    </div>
  </section>
<?php endif; ?>