<?php
/**
 * Template part for displaying slider section
 *
 * @package Air Condition Repair
 * @subpackage air_condition_repair
 */

$air_condition_repair_static_image = get_template_directory_uri() . '/assets/images/sliderimage.png';
?>
<?php if (get_theme_mod('air_condition_repair_slider_arrows', true) != '') : ?>
  <div id="slider" class="mb-md-0 mb-3">
    <div id="owl-carousel" class="slides owl-carousel">
      <?php
      $air_condition_repair_slide_pages = array();
      for ($air_condition_repair_count = 1; $air_condition_repair_count <= 3; $air_condition_repair_count++) {
          $air_condition_repair_mod = intval(get_theme_mod('air_condition_repair_slider_page' . $air_condition_repair_count, 0));
          if ($air_condition_repair_mod > 0) {
              $air_condition_repair_slide_pages[] = $air_condition_repair_mod;
          }
      }
      if (!empty($air_condition_repair_slide_pages)) :
          $air_condition_repair_args = array(
              'post_type' => 'page',
              'post__in' => $air_condition_repair_slide_pages,
              'orderby' => 'post__in'
          );
          $air_condition_repair_query = new WP_Query($air_condition_repair_args);
          if ($air_condition_repair_query->have_posts()) :
              while ($air_condition_repair_query->have_posts()) : $air_condition_repair_query->the_post(); ?>
                  <div class="item">
                      <div class="slider-border">
                          <?php if (has_post_thumbnail()) { ?>
                              <img src="<?php echo esc_url(get_the_post_thumbnail_url(get_the_ID(), 'full')); ?>" alt="<?php the_title_attribute(); ?>" />
                          <?php } else { ?>
                              <img src="<?php echo esc_url($air_condition_repair_static_image); ?>" alt="<?php esc_attr_e('Default Image', 'air-condition-repair'); ?>" />
                          <?php } ?>
                      </div>
                      <div class="carousel-caption">
                          <div class="inner_carousel">
                            <?php $air_condition_repair_short_heading = get_theme_mod('air_condition_repair_slider_short_heading', '');
                              if (!empty($air_condition_repair_short_heading)) { ?>
                                  <p class="slidetop-text mb-2"><?php echo esc_html($air_condition_repair_short_heading); ?></p>
                              <?php } ?>
                              <?php if (get_theme_mod('air_condition_repair_show_slider_title', true)) : ?>
                                <h1 class="mt-2"><a href="<?php the_permalink(); ?>" class="text-capitalize"><?php the_title(); ?></a></h1>
                              <?php endif; ?>
                              <?php if (get_theme_mod('air_condition_repair_show_slider_content', true)) : ?>
                                <p class="mt-2 slider-content"><?php $air_condition_repair_excerpt = get_the_excerpt(); echo esc_html( air_condition_repair_string_limit_words( $air_condition_repair_excerpt, esc_attr(get_theme_mod('air_condition_repair_slider_excerpt_length','15')))); ?></p>
                              <?php endif; ?>
                              <div class="more-btn mt-lg-4 mt-3">
                                <a href="<?php the_permalink(); ?>" class="text-capitalize me-lg-4 me-md-3 me-2 mb-3 slider-btn1"><?php esc_html_e('SCHEDULE YOUR SERVICE', 'air-condition-repair'); ?><i class="fas fa-arrow-right ps-5"></i></a>
                                <?php 
                                $air_condition_repair_product_btn_text1 = get_theme_mod('air_condition_repair_product_btn_text1', 'LEARN MOIRE');
                                $air_condition_repair_product_btn_link1 = get_theme_mod('air_condition_repair_product_btn_link1');
                                if (!empty($air_condition_repair_product_btn_text1) && !empty($air_condition_repair_product_btn_link1)) { ?>
                                  <a class="text-capitalize slider-btn2" href="<?php echo esc_url($air_condition_repair_product_btn_link1); ?>"><?php echo esc_html($air_condition_repair_product_btn_text1); ?><i class="fas fa-arrow-right ps-5"></i><span class="screen-reader-text"><?php echo esc_html($air_condition_repair_product_btn_text1); ?></span></a>
                                <?php } ?>
                              </div>
                          </div>
                      </div>
                  </div>
              <?php endwhile;
              wp_reset_postdata();
          else : ?>
              <div class="no-postfound"><?php esc_html_e('No slides found.', 'air-condition-repair'); ?></div>
          <?php endif;
      endif; ?>
    </div>
    <div class="bottom-sliders">
      <?php if (get_theme_mod('air_condition_repair_total_companies')) : ?>
        <p class="total-no-text"><?php echo esc_html__( 'Trusted by more than ', 'air-condition-repair' ); ?> <span class="total-no"><?php echo esc_html(get_theme_mod('air_condition_repair_total_companies')); ?></span> <?php echo esc_html__( 'worldwide', 'air-condition-repair' ); ?></p>
      <?php endif; ?>
      <?php
      $air_condition_repair_image_count = get_theme_mod('air_condition_repair_product_banner_count', 6);
      ?>
      <?php
      $air_condition_repair_image_count = get_theme_mod('air_condition_repair_posts_to_show', 6);
      ?>
      <div class="owl-carousel owl-carousel-brand">
        <?php for ($air_condition_repair_i = 1; $air_condition_repair_i <= $air_condition_repair_image_count; $air_condition_repair_i++) :
          $air_condition_repair_image_url = get_theme_mod('air_condition_repair_product_banner' . $air_condition_repair_i);
          if ($air_condition_repair_image_url) : ?>
            <div class="item product-img text-center">
              <img src="<?php echo esc_url($air_condition_repair_image_url); ?>" alt="<?php echo esc_attr__('Company Image ', 'air-condition-repair') . $air_condition_repair_i; ?>" />
            </div>
          <?php endif;
        endfor; ?>
      </div>
    </div>
  </div>
<?php endif; ?>