<?php
/**
 * Template Name: Custom Home Page
 */

get_header(); 

?>

<main role="main" id="skip_content">

  <?php do_action( 'swimming_pool_cleaning_above_slider' ); ?>

  <?php if( get_theme_mod('swimming_pool_cleaning_slider_hide', false) != '' || get_theme_mod( 'swimming_pool_cleaning_display_slider',true) != ''){ ?>
    <section id="slider" class="mw-100 m-auto p-0">
      <div id="carouselExampleCaptions" class="carousel slide" data-bs-ride="carousel"> 
        <?php $swimming_pool_cleaning_slider_page = array();
          for ( $swimming_pool_cleaning_count = 1; $swimming_pool_cleaning_count <= 4; $swimming_pool_cleaning_count++ ) {
            $swimming_pool_cleaning_mod = intval( get_theme_mod( 'swimming_pool_cleaning_slider' . $swimming_pool_cleaning_count ));
            if ( 'page-none-selected' != $swimming_pool_cleaning_mod ) {
              $swimming_pool_cleaning_slider_page[] = $swimming_pool_cleaning_mod;
            }
          }
          if( !empty($swimming_pool_cleaning_slider_page) ) :
          $swimming_pool_cleaning_args = array(
            'post_type' => 'page',
            'post__in' => $swimming_pool_cleaning_slider_page,
            'orderby' => 'post__in'
          );
          $swimming_pool_cleaning_query = new WP_Query( $swimming_pool_cleaning_args );
          if ( $swimming_pool_cleaning_query->have_posts() ) :
            $i = 1;
        ?>     
          <div class="carousel-inner" role="listbox">
            <div class="slider-bg w-100 h-100">
              <img src="<?php echo esc_url(get_theme_mod('swimming_pool_cleaning_slider_bg_image')); ?>" alt="<?php echo esc_attr( 'slider', 'swimming-pool-cleaning'); ?>" />
            </div>
            <div class="slider-content">
              <?php  while ( $swimming_pool_cleaning_query->have_posts() ) : $swimming_pool_cleaning_query->the_post(); ?>
                <div <?php if($i == 1){echo 'class="carousel-item active"';} else{ echo 'class="carousel-item"';}?>>
                  <div class="row">
                    <div class="col-lg-6 col-md-6 align-self-center">
                      <div class="inner_carousel wow zoomIn">
                        <?php if( get_theme_mod('swimming_pool_cleaning_slider_small_title') != '' ){ ?>
                          <div class="mb-1">
                            <span class="slider-badge mb-1"><?php echo esc_html(get_theme_mod('swimming_pool_cleaning_slider_small_title',''));?></span>
                          </div>
                        <?php }?>
                        <?php if( get_theme_mod('swimming_pool_cleaning_slider_heading',true) != ''){ ?>
                          <?php
                            $swimming_pool_cleaning_title = get_the_title();
                            $swimming_pool_cleaning_words = explode(' ', $swimming_pool_cleaning_title);
                            $swimming_pool_cleaning_word_count = count($swimming_pool_cleaning_words);

                            if ($swimming_pool_cleaning_word_count >= 2) {
                                $swimming_pool_cleaning_before = implode(' ', array_slice($swimming_pool_cleaning_words, 0, -2));
                                $swimming_pool_cleaning_last_two = implode(' ', array_slice($swimming_pool_cleaning_words, -2));
                                echo '<h1 class="text-capitalise">' . esc_html($swimming_pool_cleaning_before) . '<br><span class="slider-heading">' . esc_html($swimming_pool_cleaning_last_two) . '</span></h1>';
                            } else {
                                echo '<h1 class="text-capitalise">' . esc_html($swimming_pool_cleaning_title) . '</h1>';
                            }
                          ?>
                        <?php } ?>
                        <?php if( get_theme_mod('swimming_pool_cleaning_slider_text',true) != ''){ ?>
                          <p class="my-3"><?php $swimming_pool_cleaning_excerpt = get_the_excerpt(); echo esc_html( swimming_pool_cleaning_string_limit_words( $swimming_pool_cleaning_excerpt, esc_attr(get_theme_mod('swimming_pool_cleaning_slider_excerpt_number','20')))); ?></p>
                        <?php } ?>
                        <?php if (get_theme_mod( 'swimming_pool_cleaning_show_slider_button',true) != '' || get_theme_mod( 'swimming_pool_cleaning_display_slider_button',true) != ''){ ?>
                          <?php if( get_theme_mod('swimming_pool_cleaning_slider_button_text','View All Services') != '' || get_theme_mod('swimming_pool_cleaning_slider_button_link') != ''){ ?>
                            <div class="slide-button mt-md-3">
                              <a class="read-more" href="<?php echo esc_url(get_theme_mod('swimming_pool_cleaning_slider_button_link')!= '') ? esc_url(get_theme_mod('swimming_pool_cleaning_slider_button_link')) : esc_url(get_permalink()); ?>"><?php echo esc_html( get_theme_mod('swimming_pool_cleaning_slider_button_text',__('View All Services','swimming-pool-cleaning'))); ?><span class="screen-reader-text"><?php echo esc_html( get_theme_mod('swimming_pool_cleaning_slider_button_text',__('View All Services','swimming-pool-cleaning'))); ?></span></a>
                            </div> 
                          <?php }?>  
                        <?php } ?>
                      </div>
                    </div>
                    <div class="col-lg-6 col-md-6 slider-img align-self-center wow bounceIn">
                      <?php if(has_post_thumbnail()){
                        the_post_thumbnail();
                      } ?>
                    </div>
                  </div>
                </div>
              <?php $i++; endwhile; 
              wp_reset_postdata();?>
            </div>
          </div>
        <?php else : ?>
          <div class="no-postfound"></div>
        <?php endif;
        endif;?>
        <a class="carousel-control-prev" data-bs-target="#carouselExampleCaptions" data-bs-slide="prev" role="button">
          <span class="carousel-control-prev-icon w-auto h-auto" aria-hidden="true"><i class="<?php echo esc_attr(get_theme_mod('swimming_pool_cleaning_slider_previous_icon','fas fa-chevron-left')); ?>" ></i></span>
          <span class="screen-reader-text"><?php esc_html_e( 'Previous','swimming-pool-cleaning' );?></span>
        </a>
        <a class="carousel-control-next" data-bs-target="#carouselExampleCaptions" data-bs-slide="next" role="button">
          <span class="carousel-control-next-icon w-auto h-auto" aria-hidden="true"><i class="<?php echo esc_attr(get_theme_mod('swimming_pool_cleaning_slider_next_icon','fas fa-chevron-right')); ?>" ></i></span>
          <span class="screen-reader-text"><?php esc_html_e( 'Next','swimming-pool-cleaning' );?></span>
        </a>
      </div>  
      <div class="clearfix"></div>
    </section>
  <?php }?>
  
  <?php do_action( 'swimming_pool_cleaning_below_slider' ); ?>

  <?php if( get_theme_mod( 'swimming_pool_cleaning_choose_us_enable',false) != false) { ?>
    <section id="service-section" class="py-5 wow bounceInDown">
      <div class="service-head">
        <div class="container">
          <?php if(get_theme_mod('swimming_pool_cleaning_section_small_title') != '') {?>
            <p class="text-center"><?php echo esc_html(get_theme_mod('swimming_pool_cleaning_section_small_title')); ?></p>
          <?php }?>
          <?php if(get_theme_mod('swimming_pool_cleaning_section_title') != '') {?>
            <h3 class="text-center my-2"><?php echo esc_html(get_theme_mod('swimming_pool_cleaning_section_title')); ?></h3>
          <?php }?>
        </div>
      </div>
      <div class="container">
        <div class="row">
          <div class="col-lg-6 col-md-6 serv-img">
            <img src="<?php echo esc_url(get_theme_mod('swimming_pool_cleaning_service_image')); ?>" alt="<?php echo esc_attr( 'service-image', 'swimming-pool-cleaning'); ?>" />
          </div>
          <div class="col-lg-6 col-md-6 cat-sec">
            <div class="row">
            <?php if ( get_theme_mod('swimming_pool_cleaning_serv_category') != '' ) {
              $i = 1;
              $swimming_pool_cleaning_page_query = new WP_Query(array( 
                'category_name' => esc_html(get_theme_mod('swimming_pool_cleaning_serv_category')),
                'posts_per_page' => get_theme_mod('swimming_pool_cleaning_choose_us_posts_number', 4)
              )); ?>
              <?php while( $swimming_pool_cleaning_page_query->have_posts() ) : $swimming_pool_cleaning_page_query->the_post(); ?>
                <div class="col-lg-6 col-md-12">
                  <div class="post-box">
                    <div class="row">
                      <div class="col-lg-6 col-md-6 col-6">
                        <div class="service-icon">
                          <i class="<?php echo esc_attr(get_theme_mod('swimming_pool_cleaning_service_posts_icon' . $i, 'fas fa-wrench')); ?>"></i>
                        </div>
                      </div>
                      <div class="col-lg-6 col-md-6 col-6">
                        <div class="service-num">
                          <span><?php if($i <=9 ) { echo esc_html(0); } echo esc_html($i); ?></span>
                        </div>
                      </div> 
                    </div>
                    <div class="post_content mt-4">
                      <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?><span class="screen-reader-text"><?php the_title(); ?></span></a></h4>
                    </div>
                  </div>
                </div>
              <?php $i++; endwhile; wp_reset_query(); ?>
            <?php } ?>
          </div>
          </div>
        </div>
      </div>
    </section>
  <?php } ?> 

  <div class="container front-page-content">
    <?php while ( have_posts() ) : the_post(); ?>
      <div class="new-text"><?php the_content(); ?></div>
    <?php endwhile; // end of the loop. ?>
  </div>
</main>

<?php get_footer(); ?>