<?php
/**
 * Template part for displaying slider section
 *
 * @package Notary Services
 * @subpackage notary_services
 */

$notary_services_static_image = get_template_directory_uri() . '/assets/images/slider-img.png';
$notary_services_slider_arrows = get_theme_mod('notary_services_slider_arrows', true);

?>
<?php if ($notary_services_slider_arrows) : ?>
  <section id="slider" style="background-image: url('<?php echo get_stylesheet_directory_uri(); ?>/assets/images/sliderbg1.png');">
    <div class="container">
      <div class="owl-carousel owl-theme">
        <?php 
        $notary_services_slide_pages = array();
        for ($notary_services_count = 1; $notary_services_count <= 4; $notary_services_count++) {
          $mod = absint(get_theme_mod('notary_services_slider_page' . $notary_services_count));
          if ($mod != 0) {
            $notary_services_slide_pages[] = $mod;
          }
        }

        if (!empty($notary_services_slide_pages)) :
          $notary_services_args = array(
            'post_type' => 'page',
            'post__in' => $notary_services_slide_pages,
            'orderby' => 'post__in'
          );
          $notary_services_query = new WP_Query($notary_services_args);
          if ($notary_services_query->have_posts()) :
            while ($notary_services_query->have_posts()) : $notary_services_query->the_post(); ?>
              <div class="item">
                <div class="row m-0">
                  <div class="col-lg-6 col-md-6 col-12 slider-content-col align-self-center">
                    <div class="carousel-caption">
                      <div class="inner_carousel">
                        <?php if (get_theme_mod('notary_services_slider_short_heading')) : ?>
                          <p class="slidetop-text mb-2 text-uppercase"><?php echo esc_html(get_theme_mod('notary_services_slider_short_heading')); ?></p>
                        <?php endif; ?>
                        <?php if (get_theme_mod('notary_services_show_slider_title', true)) : ?>
                          <h1 class="mb-md-3 mb-0"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
                        <?php endif; ?>
                        <?php if (get_theme_mod('notary_services_show_slider_content', true)) : ?>
                          <?php $notary_services_excerpt = get_the_excerpt(); echo esc_html( notary_services_string_limit_words( $notary_services_excerpt, esc_attr(get_theme_mod('notary_services_slider_excerpt_length','28')))); ?></p>
                        <?php endif; ?>
                        <div class="more-btn mt-4">
                          <a class="text-capitalize me-2 mb-3 slider-btn1" href="<?php the_permalink(); ?>" target="_blank">
                              <?php esc_html_e( 'DISCOVER MORE', 'notary-services' ); ?>
                          </a>
                        </div>
                      </div>
                    </div>
                  </div>
                  <div class="col-lg-6 col-md-6 col-12 slider-img-col">
                    <?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($notary_services_static_image); ?>" alt="<?php esc_attr_e('Slider Image', 'notary-services'); ?>" />
                    <?php endif; ?>
                  </div>
                </div>
              </div>
            <?php endwhile;
            wp_reset_postdata();
          else : ?>
            <div class="no-postfound"><?php esc_html_e('No posts found', 'notary-services'); ?></div>
          <?php endif;
        endif; ?>
      </div>
    </div>
    <div class="clearfix"></div>
  </section>
<?php endif; ?>