<?php
/**
 * Template part for displaying slider section
 *
 * @package Packers And Movers
 * @subpackage packers_and_movers
 */

$packers_and_movers_static_image = get_template_directory_uri() . '/assets/images/slider-img.png';

$packers_and_movers_slider_arrows = get_theme_mod('packers_and_movers_slider_arrows', true);
?>
<?php if ($packers_and_movers_slider_arrows) : ?>
  <section id="slider" style="background-image: url('<?php echo get_stylesheet_directory_uri(); ?>/assets/images/sliderimage.png'); border-radius: 40px;">
      <div class="owl-carousel owl-theme">
        <?php 
        $packers_and_movers_slide_pages = array();
        for ($packers_and_movers_count = 1; $packers_and_movers_count <= 4; $packers_and_movers_count++) {
          $mod = absint(get_theme_mod('packers_and_movers_slider_page' . $packers_and_movers_count));
          if ($mod != 0) {
            $packers_and_movers_slide_pages[] = $mod;
          }
        }

        if (!empty($packers_and_movers_slide_pages)) :
          $packers_and_movers_args = array(
            'post_type' => 'page',
            'post__in' => $packers_and_movers_slide_pages,
            'orderby' => 'post__in'
          );
          $packers_and_movers_query = new WP_Query($packers_and_movers_args);
          if ($packers_and_movers_query->have_posts()) :
            while ($packers_and_movers_query->have_posts()) : $packers_and_movers_query->the_post(); ?>
              <div class="item">
                <div class="row m-0">
                  <div class="col-lg-6 col-md-7 col-12 slider-content-col align-self-center">
                    <div class="carousel-caption">
                      <div class="inner_carousel">
                        <?php if (get_theme_mod('packers_and_movers_slider_short_heading')) : ?>
                          <p class="slidetop-text mb-2 text-uppercase"><?php echo esc_html(get_theme_mod('packers_and_movers_slider_short_heading')); ?></p>
                        <?php endif; ?>
                        <?php if (get_theme_mod('packers_and_movers_show_slider_title', true)) : ?>
                          <h1 class="mb-md-3 mb-0">
                            <a href="<?php the_permalink(); ?>" class="text-capitalize"><?php the_title();?></a>
                          </h1>
                        <?php endif; ?>
                        <?php if (get_theme_mod('packers_and_movers_show_slider_content', true)) : ?>
                          <p class="mb-0 content-slider"><?php $packers_and_movers_excerpt = get_the_excerpt(); echo esc_html( packers_and_movers_string_limit_words( $packers_and_movers_excerpt, esc_attr(get_theme_mod('packers_and_movers_slider_excerpt_length','21')))); ?></p>
                        <?php endif; ?>
                      </div>
                    </div>
                  </div>
                  <div class="col-lg-6 col-md-5 col-12 slider-img-col align-self-center">
                    <?php if (has_post_thumbnail()) : ?>
                      <img src="<?php the_post_thumbnail_url('full'); ?>" alt="<?php the_title_attribute(); ?>" />
                    <?php else : ?>
                      <img src="<?php echo esc_url($packers_and_movers_static_image); ?>" alt="<?php esc_attr_e('Slider Image', 'packers-and-movers'); ?>" />
                    <?php endif; ?>
                  </div>
                </div>
              </div>
            <?php endwhile;
            wp_reset_postdata();
          else : ?>
            <div class="no-postfound"><?php esc_html_e('No posts found', 'packers-and-movers'); ?></div>
          <?php endif;
        endif; ?>
      </div>

      <!-- slider number pagination -->
      <div class="slide-number">
        <span class="current-number"><?php echo esc_html__('01', 'packers-and-movers'); ?></span><span class="seperator"><?php echo esc_html__('/', 'packers-and-movers'); ?></span><span class="next-number"><?php echo esc_html__('02', 'packers-and-movers'); ?></span>
      </div>

    <div class="clearfix"></div>
  </section>
<?php endif; ?>
