<?php
/**
 * Template part for displaying slider section
 *
 * @package SAAS Agency
 * @subpackage SAAS Agency
 */

$saas_agency_static_image  = get_template_directory_uri() . '/assets/images/slider-img.png';
$saas_agency_static_image1 = get_template_directory_uri() . '/assets/images/post-img1.png';
$saas_agency_slider_arrows = get_theme_mod('saas_agency_slider_arrows', true);
?>

<?php if ($saas_agency_slider_arrows) : ?>
  <section id="slider" style="background-image: url('<?php echo esc_url(get_template_directory_uri() . '/assets/images/slider-bg.png'); ?>');">
    <div class="container">
      <div class="slide">
        <?php 
        $saas_agency_slide_pages = array();
        for ($saas_agency_count = 1; $saas_agency_count <= 1; $saas_agency_count++) {
          $mod = absint(get_theme_mod('saas_agency_slider_page' . $saas_agency_count));
          if ($mod != 0) {
            $saas_agency_slide_pages[] = $mod;
          }
        }

        if (!empty($saas_agency_slide_pages)) :
          $saas_agency_args = array(
            'post_type'   => 'page',
            'post__in'    => $saas_agency_slide_pages,
            'orderby'     => 'post__in',
          );
          $saas_agency_query = new WP_Query($saas_agency_args);
          if ($saas_agency_query->have_posts()) :
            while ($saas_agency_query->have_posts()) : $saas_agency_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 p-0">
                    <div class="carousel-caption">
                      <div class="inner_carousel">
                        <?php if (get_theme_mod('saas_agency_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('saas_agency_show_slider_content', true)) : ?>
                          <p class="mb-0 slide-content"><?php $saas_agency_excerpt = get_the_excerpt(); echo esc_html( saas_agency_string_limit_words( $saas_agency_excerpt, esc_attr(get_theme_mod('saas_agency_slider_excerpt_length','28')))); ?></p>
                        <?php endif; ?>

                        <div class="site-search my-4">
                          <form method="get" class="search-form" action="<?php echo esc_url(home_url('/')); ?>">
                            <input type="search" id="search-field" class="search-field"
                              placeholder="<?php echo esc_attr__('Enter your email', 'saas-agency'); ?>"
                              value="<?php echo esc_attr(get_search_query()); ?>" name="s" />

                            <button type="submit" class="search-submit">
                              <span><?php echo esc_html__('Start Your Free Trial', 'saas-agency'); ?></span>
                            </button>
                          </form>
                        </div>

                        <div class="rating-col">
                          <div class="row rating-box">
                            <div class="col-lg-4 col-md-4 col-5 align-self-center px-0 position-relative">
                              <?php 
                              $saas_agency_selected_category = get_theme_mod('saas_agency_about_catData', 'select');
                              if ($saas_agency_selected_category !== 'select') : ?>
                                <div class="abt-cat">
                                  <div class="abt owl-carousel m-0">
                                    <?php
                                    $saas_agency_abtpage_query = new WP_Query(array(
                                      'category_name'   => esc_attr($saas_agency_selected_category),
                                      'posts_per_page'  => -1,
                                    ));
                                    if ($saas_agency_abtpage_query->have_posts()) :
                                      while ($saas_agency_abtpage_query->have_posts()) : $saas_agency_abtpage_query->the_post(); ?>
                                        <div class="abt-imagebox">
                                          <?php if (has_post_thumbnail()) : ?>
                                            <img src="<?php the_post_thumbnail_url(); ?>" alt="<?php echo esc_attr(get_the_title()); ?>" />
                                          <?php else : ?>
                                            <img src="<?php echo esc_url($saas_agency_static_image1); ?>" alt="<?php esc_attr_e('Default image', 'saas-agency'); ?>" />
                                          <?php endif; ?>
                                        </div>
                                      <?php endwhile;
                                      wp_reset_postdata();
                                    else : ?>
                                      <p><?php esc_html_e('No posts found in this category.', 'saas-agency'); ?></p>
                                    <?php endif; ?>
                                  </div>
                                </div>
                              <?php endif; ?>
                            </div>

                            <div class="col-lg-8 col-md-8 col-7 align-self-center">
                              <?php if (get_theme_mod('saas_agency_slider_total_user')) : ?>
                                <p class="slidetop-text"><?php echo esc_html(get_theme_mod('saas_agency_slider_total_user')); ?></p>
                              <?php endif; ?>
                            </div>
                          </div>
                        </div> <!-- .rating-col -->
                      </div>
                    </div>
                  </div>

                  <div class="col-lg-6 col-md-6 col-12 slider-img-col position-relative">
                    <div class="slider-img-wrapper position-relative">
                      <?php if (has_post_thumbnail()) : ?>
                        <img class="slider-main-img" src="<?php the_post_thumbnail_url('full'); ?>" alt="<?php echo esc_attr(get_the_title()); ?>" />
                      <?php else : ?>
                        <img class="slider-main-img" src="<?php echo esc_url($saas_agency_static_image); ?>" alt="<?php esc_attr_e('Slider Image', 'saas-agency'); ?>" />
                      <?php endif; ?>

                      <?php 
                      $saas_agency_top_right_img    = get_theme_mod('saas_agency_slider_top_right_image');
                      $saas_agency_bottom_left_img  = get_theme_mod('saas_agency_slider_bottom_left_image');
                      ?>
                      <div class="right-img">
                        <?php if ($saas_agency_top_right_img) : ?>
                          <img src="<?php echo esc_url($saas_agency_top_right_img); ?>" class="overlay-image top-right" alt="<?php esc_attr_e('Top Right Overlay', 'saas-agency'); ?>" />
                        <?php endif; ?>
                      </div>

                      <div class="left-img">
                        <?php if ($saas_agency_bottom_left_img) : ?>
                          <img src="<?php echo esc_url($saas_agency_bottom_left_img); ?>" class="overlay-image bottom-left" alt="<?php esc_attr_e('Bottom Left Overlay', 'saas-agency'); ?>" />
                        <?php endif; ?>
                      </div>
                    </div>
                  </div>
                </div> <!-- .row -->
              </div> <!-- .item -->
            <?php endwhile;
            wp_reset_postdata();
          else : ?>
            <div class="no-postfound"><?php esc_html_e('No posts found', 'saas-agency'); ?></div>
          <?php endif;
        endif; ?>
      </div> <!-- .slide -->
    </div> <!-- .container -->
    <div class="clearfix"></div>
  </section>
<?php endif; ?>