<?php
/**
 * Template part for displaying services section
 *
 * @package Online Startup Agency
 * @subpackage online_startup_agency
 */
?>

<?php $online_startup_agency_static_image = get_stylesheet_directory_uri() . '/assets/images/post-img1.png'; ?>

<?php if (get_theme_mod('online_startup_agency_show_hide_sec', true)) : ?>
  <section id="service-sec" class="py-5 px-md-0 px-3">
    <div class="container">
      <div class="text-center">
        <?php if (get_theme_mod('online_startup_agency_featured_section_title')) : ?>
          <h2 class="text-center mb-2 text-capitalize">
            <?php echo esc_html(get_theme_mod('online_startup_agency_featured_section_title', '')); ?>
          </h2>
        <?php endif; ?>
        <?php if (get_theme_mod('online_startup_agency_serv_short_heading') != '') { ?>
          <p class="serv-short mb-3 text-center d-inline-block text-capitalize">
            <?php echo esc_html(get_theme_mod('online_startup_agency_serv_short_heading', '')); ?>
          </p>
        <?php } ?>
      </div>

      <!-- Owl Carousel wrapper -->
      <div class="owl-carousel services-carousel">
        <?php
          $online_startup_agency_post_category = get_theme_mod('online_startup_agency_featured_section_category');
          $online_startup_agency_num_posts = get_theme_mod('online_startup_agency_num_posts', 3); 

          if ($online_startup_agency_post_category) :
            $online_startup_agency_page_query = new WP_Query(array(
              'category_name' => esc_html($online_startup_agency_post_category),
              'posts_per_page' => $online_startup_agency_num_posts,
            ));

            if ($online_startup_agency_page_query->have_posts()) :
              while ($online_startup_agency_page_query->have_posts()) : $online_startup_agency_page_query->the_post(); ?>
                
                <div class="item"> <!-- Each carousel item -->
                  <div class="cat-inner-box">
                    <div class="post-imgs">
                      <?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 : ?>
                        <img src="<?php echo esc_url($online_startup_agency_static_image); ?>" alt="<?php esc_attr_e('Default Image', 'online-startup-agency'); ?>">
                      <?php endif; ?>
                      <div class="corner-fold-bl"></div>
                      <?php 
                        $online_startup_agency_services_icon = get_theme_mod(
                            'online_startup_agency_services_icon' . ($online_startup_agency_page_query->current_post + 1),
                            'fas fa-headset'
                        );
                        if ($online_startup_agency_services_icon) : ?>
                          <div class="icon">
                            <i class="<?php echo esc_attr($online_startup_agency_services_icon); ?> main-icon"></i>
                          </div>
                      <?php endif; ?>
                    </div>
                    <div class="inner-content">
                      <div class="post-title text-center">
                        <h3 class="mt-2 mb-1"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                        <p class="mb-0"><?php echo wp_trim_words(get_the_content(), 8); ?></p>
                      </div>
                    </div>
                  </div>
                </div>

              <?php endwhile;
              wp_reset_postdata();
            endif;
          endif;
        ?>
      </div><!-- /.owl-carousel -->
    </div>
  </section>
<?php endif; ?>