<?php
/**
 * Template part for displaying services section
 *
 * @package Window Blinds Repair
 * @subpackage window_blinds_repair
 */
?>

<?php $window_blinds_repair_static_image = get_stylesheet_directory_uri() . '/assets/images/header_img.png'; ?>

<?php if (get_theme_mod('window_blinds_repair_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('window_blinds_repair_serv_short_heading') != '') { ?>
          <p class="serv-short text-center d-inline-block text-capitalize"><?php echo esc_html(get_theme_mod('window_blinds_repair_serv_short_heading', '')); ?></p>
        <?php } ?>
        <?php if (get_theme_mod('window_blinds_repair_featured_section_title')) : ?>
          <h2 class="text-center mb-lg-5 mb-4 text-capitalize"><?php echo esc_html(get_theme_mod('window_blinds_repair_featured_section_title', '')); ?></h2>
        <?php endif; ?>
      </div>
      <div class="row">
        <?php
          $window_blinds_repair_post_category = get_theme_mod('window_blinds_repair_featured_section_category');
          $window_blinds_repair_num_posts = get_theme_mod('window_blinds_repair_num_posts', 3); 

          if ($window_blinds_repair_post_category) :
            $window_blinds_repair_page_query = new WP_Query(array(
              'category_name' => esc_html($window_blinds_repair_post_category),
              'posts_per_page' => $window_blinds_repair_num_posts,
            ));

            if ($window_blinds_repair_page_query->have_posts()) :
              while ($window_blinds_repair_page_query->have_posts()) : $window_blinds_repair_page_query->the_post(); ?>
                <div class="col-lg-4 col-md-6 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 the_title_attribute(); ?>" />
                    <?php else : ?>
                      <img src="<?php echo esc_url($window_blinds_repair_static_image); ?>" alt="<?php esc_attr_e('Default Image', 'window-blinds-repair'); ?>">
                    <?php endif; ?>
                    <div class="inner-content">
                      <div class="row">
                        <div class="col-lg-9 col-md-9 col-9 post-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(), 12); ?></p>
                          </div>
                          <div class="more-details">
                            <a href="<?php the_permalink(); ?>"><?php esc_html_e('More Details', 'window-blinds-repair'); ?><i class="fas fa-arrow-right ms-2"></i></a>
                          </div>
                        </div>
                        <div class="col-lg-3 col-md-3 col-3 post-icon">
                          <?php 
                            $window_blinds_repair_services_icon = get_theme_mod('window_blinds_repair_services_icon' . ($window_blinds_repair_page_query->current_post + 1));
                            if ($window_blinds_repair_services_icon) : 
                          ?>
                            <div class="icon">
                              <i class="<?php echo esc_attr($window_blinds_repair_services_icon,'far fa-window-maximize'); ?> main-icon"></i>
                            </div>
                          <?php endif; ?>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              <?php endwhile;
              wp_reset_postdata();
            endif;
          endif;
        ?>
      </div>
    </div>
  </section>
<?php endif; ?>
