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

<?php get_header(); ?>

<main id="main" role="main">
  <?php do_action( 'cleaning_business_above_slider' ); ?>

  <?php
  $cleaning_business_content_pages = array();
  for ( $count = 1; $count <= 4; $count++ ) {
    $mod = intval( get_theme_mod( 'cleaning_business_slider_page' . $count ));
    if ( 'page-none-selected' != $mod ) {
      $cleaning_business_content_pages[] = $mod;
    }
  }
  ?>

  <section id="slider" class="mw-100">
    <div class="s-oly"></div>
    <div class="container">
      <div id="carouselExampleCaptions" class="carousel slide" data-bs-ride="carousel">
        <?php
        if ( ! empty( $cleaning_business_content_pages ) ) {
          $args = array(
            'post_type' => 'page',
            'post__in' => $cleaning_business_content_pages,
            'orderby' => 'post__in'
          );
          $query = new WP_Query( $args );

          if ( $query->have_posts() ) :
            $i = 1;
            ?>
            <div class="carousel-inner" role="listbox">
              <?php while ( $query->have_posts() ) : $query->the_post(); ?>
                <div class="carousel-item <?php echo ( $i === 1 ) ? 'active' : ''; ?>">
                  <div class="row m-0">
                    <div class="col-xl-5 col-lg-6 col-md-6 col-sm-5">
                      <div class="sliderbg-img">
                        <?php the_post_thumbnail(); ?>
                      </div>
                    </div>
                    <div class="col-xl-7 col-lg-6 col-md-6 col-sm-7 pd-0">
                      <div class="slider-content">
                        <div class="inner_carousel">
                          <p>
                            <?php 
                            $excerpt = get_the_excerpt(); 
                            echo esc_html( cleaning_business_string_limit_words( $excerpt, 20 ) ); 
                            ?>
                          </p>
                          <h2><?php the_title(); ?></h2>
                          <div class="sliderlist">
                            <div class="row m-0">
                              <div class="col-lg-6 col-md-6 col-sm-6 pd-0">
                                <ul>
                                  <li><i class="fa fa-check-square-o"></i> <?php echo esc_html(get_theme_mod('cleaning_business_sliderlist1')); ?></li>
                                  <li><i class="fa fa-check-square-o"></i> <?php echo esc_html(get_theme_mod('cleaning_business_sliderlist2')); ?></li>
                                </ul>
                              </div>
                              <div class="col-lg-6 col-md-6 col-sm-6 pd-0">
                                <ul>
                                  <li><i class="fa fa-check-square-o"></i> <?php echo esc_html(get_theme_mod('cleaning_business_sliderlist3')); ?></li>
                                  <li><i class="fa fa-check-square-o"></i> <?php echo esc_html(get_theme_mod('cleaning_business_sliderlist4')); ?></li>
                                </ul>
                              </div>
                            </div>
                          </div>
                          <div class="clearfix"></div>
                          <div class="read-btn">
                            <a href="<?php the_permalink(); ?>"><?php esc_html_e('Read More', 'cleaning-business'); ?></a>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <?php $i++; endwhile; wp_reset_postdata(); ?>
            </div>
          <?php else : ?>
            <div class="carousel-inner" role="listbox">
              <div class="carousel-item active">
                <div class="row m-0">
                  <div class="col-xl-5 col-lg-6 col-md-6 col-sm-5">
                    <div class="sliderbg-img">
                      <img src="<?php echo esc_url(get_template_directory_uri() . '/assets/images/slider1.png'); ?>" alt="Default Image">
                    </div>
                  </div>
                  <div class="col-xl-7 col-lg-6 col-md-6 col-sm-7 pd-0">
                    <div class="slider-content">
                      <div class="inner_carousel">
                        <p><?php esc_html_e('The best and professional', 'cleaning-business'); ?></p>
                        <h2><?php esc_html_e('cleaning services', 'cleaning-business'); ?></h2>
                        <div class="sliderlist">
                          <div class="row m-0">
                            <div class="col-lg-6 col-md-6 col-sm-6 pd-0">
                              <ul>
                                <li><i class="fa fa-check-square-o"></i> <?php esc_html_e('Lorem Ipsum', 'cleaning-business'); ?></li>
                                <li><i class="fa fa-check-square-o"></i> <?php esc_html_e('Lorem Ipsum', 'cleaning-business'); ?></li>
                              </ul>
                            </div>
                            <div class="col-lg-6 col-md-6 col-sm-6 pd-0">
                              <ul>
                                <li><i class="fa fa-check-square-o"></i> <?php esc_html_e('Lorem Ipsum', 'cleaning-business'); ?></li>
                                <li><i class="fa fa-check-square-o"></i> <?php esc_html_e('Lorem Ipsum', 'cleaning-business'); ?></li>
                              </ul>
                            </div>
                          </div>
                        </div>
                        <div class="clearfix"></div>
                        <div class="read-btn">
                          <a href="#"><?php esc_html_e('Read More', 'cleaning-business'); ?></a>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          <?php endif;
        } else {
          // Show default static slide
          ?>
          <div class="carousel-inner" role="listbox">
            <div class="carousel-item active">
              <div class="row m-0">
                <div class="col-xl-5 col-lg-6 col-md-6 col-sm-5">
                  <div class="sliderbg-img">
                    <img src="<?php echo esc_url(get_template_directory_uri() . '/assets/images/slider1.png'); ?>" alt="Default Image">
                  </div>
                </div>
                <div class="col-xl-7 col-lg-6 col-md-6 col-sm-7 pd-0">
                  <div class="slider-content">
                    <div class="inner_carousel">
                      <p><?php esc_html_e('The best and professional', 'cleaning-business'); ?></p>
                      <h2><?php esc_html_e('cleaning services', 'cleaning-business'); ?></h2>
                      <div class="sliderlist">
                        <div class="row m-0">
                          <div class="col-lg-6 col-md-6 col-sm-6 pd-0">
                            <ul>
                              <li><i class="fa fa-check-square-o"></i> <?php esc_html_e('Lorem Ipsum', 'cleaning-business'); ?></li>
                              <li><i class="fa fa-check-square-o"></i> <?php esc_html_e('Lorem Ipsum', 'cleaning-business'); ?></li>
                            </ul>
                          </div>
                          <div class="col-lg-6 col-md-6 col-sm-6 pd-0">
                            <ul>
                              <li><i class="fa fa-check-square-o"></i> <?php esc_html_e('Lorem Ipsum', 'cleaning-business'); ?></li>
                              <li><i class="fa fa-check-square-o"></i> <?php esc_html_e('Lorem Ipsum', 'cleaning-business'); ?></li>
                            </ul>
                          </div>
                        </div>
                      </div>
                      <div class="clearfix"></div>
                      <div class="read-btn">
                        <a href="#"><?php esc_html_e('Read More', 'cleaning-business'); ?></a>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <?php
        }
        ?>
        <a class="carousel-control-prev" data-bs-target="#carouselExampleCaptions" data-bs-slide="prev" role="button">
          <span class="carousel-control-prev-icon" aria-hidden="true"><i class="fas fa-caret-left"></i></span>
          <span class="screen-reader-text"><?php esc_html_e('Previous', 'cleaning-business'); ?></span>
        </a>
        <a class="carousel-control-next" data-bs-target="#carouselExampleCaptions" data-bs-slide="next" role="button">
          <span class="carousel-control-next-icon" aria-hidden="true"><i class="fas fa-caret-right"></i></span>
          <span class="screen-reader-text"><?php esc_html_e('Next', 'cleaning-business'); ?></span>
        </a>
      </div>
      <div class="clearfix"></div>
    </div>
  </section>

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

  <section id="service-section">
    <div class="container">
      <?php
      $service_heading = get_theme_mod('cleaning_business_btn_serviceheading');
      $cleaning_business_catData = get_theme_mod('cleaning_business_service_category');
      $has_posts = false;

      if ($cleaning_business_catData) {
        $page_query = new WP_Query(array(
          'category_name' => esc_html($cleaning_business_catData, 'cleaning-business')
        ));

        if ($page_query->have_posts()) {
          $has_posts = true;
          if ($service_heading != '') {
            ?>
            <div class="service-head">
              <h4>
                <?php echo esc_html($service_heading); ?>
                <div class="heading-brd"></div>
              </h4>
            </div>
            <?php
          }
          ?>
          <div class="row mr-0">
            <?php while ($page_query->have_posts()) : $page_query->the_post(); ?>
              <div class="col-lg-4 col-md-6 col-sm-6 serbx">
                <div class="service-box text-center">
                  <div class="service-img">
                    <?php the_post_thumbnail(); ?>
                    <div class="ser_oly"></div>
                    <div class="service-content">
                      <a href="<?php echo esc_url(get_permalink()); ?>">
                        <div class="title"><?php the_title(); ?></div>
                      </a>
                    </div>
                    <div class="clearfix"></div>
                  </div>
                </div>
                <div class="clearfix"></div>
              </div>
            <?php endwhile;
            wp_reset_postdata(); ?>
          </div>
          <?php
        }
      }

      // Show static content if no dynamic content found
      if (!$has_posts) {
        ?>
        <div class="service-head">
          <h4>
            <?php esc_html_e('CLEANING SERVICES', 'cleaning-business'); ?>
            <div class="heading-brd"></div>
          </h4>
        </div>
        <div class="row mr-0">
          <?php
          $static_services = array(
            array(
              'title' => 'GARDEN CLEANING',
              'image' => get_template_directory_uri() . '/assets/images/services1.png'
            ),
            array(
              'title' => 'APARTMENT CLEANING',
              'image' => get_template_directory_uri() . '/assets/images/services2.png'
            ),
            array(
              'title' => 'COMMERCIAL CLEANING',
              'image' => get_template_directory_uri() . '/assets/images/services3.png'
            )
          );

          foreach ($static_services as $service) : ?>
            <div class="col-lg-4 col-md-6 col-sm-6 serbx">
              <div class="service-box text-center">
                <div class="service-img">
                  <img src="<?php echo esc_url($service['image']); ?>" alt="<?php echo esc_attr($service['title']); ?>">
                  <div class="ser_oly"></div>
                  <div class="service-content">
                    <a href="#">
                      <div class="title"><?php esc_html_e($service['title'], 'cleaning-business'); ?></div>
                    </a>
                  </div>
                  <div class="clearfix"></div>
                </div>
              </div>
              <div class="clearfix"></div>
            </div>
          <?php endforeach; ?>
        </div>
      <?php } ?>
    </div>
    <div class="clearfix"></div>
  </section>

  <?php if( get_theme_mod('cleaning_business_service_category') != ''){ ?>

    <section id="aboutus-section">
      <div class="container">
        <?php if(get_theme_mod('cleaning_business_aboutustitle') != ''){ ?>
          <div class="service-head">
            <h4>
              <?php echo esc_html(get_theme_mod('cleaning_business_aboutustitle', 'About us')); ?>
              <div class="heading-brd"></div>
            </h4>
          </div>
        <?php }?>
        <div class="row m-0">
          <div class="col-lg-5 col-md-12 col-sm-12">
            <div class="yearofex">
              <h3 class="yearofexno"><?php echo esc_html(get_theme_mod('cleaning_business_aboutusyearofexno', '30')); ?></h3>
              <p class="yearofextext"><?php echo esc_html(get_theme_mod('cleaning_business_aboutusyearofextext', 'Years Of Experience We Provides')); ?></p>
            </div>

            <div class="aboutus-content">
              <p class="description"><?php echo esc_html(get_theme_mod('cleaning_business_aboutusdescription', 'Lorem Ipsum is simply dummy text of the printing and type setting industry. Lorem Ipsum has been the industry standard dummy text since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.')); ?></p>
              <ul>
                <li><?php echo esc_html(get_theme_mod('cleaning_business_aboutuslist1', 'It has survived not only five centuries.')); ?></li>
                <li><?php echo esc_html(get_theme_mod('cleaning_business_aboutuslist2', 'It has survived not only five centuries.')); ?></li>
              </ul>
              <div class="aboutus-btn">
                <?php if(get_theme_mod('cleaning_business_aboutusbtntext') != '') {?>
                  <a href="<?php echo esc_html(get_theme_mod('cleaning_business_aboutusbtnlinks', '#')); ?>"><?php echo esc_html(get_theme_mod('cleaning_business_aboutusbtntext', 'Contact Us')); ?></a>
                <?php }?>
              </div>
            </div>
          </div> 

          <div class="col-lg-7 col-md-12 col-sm-12">
            <div class="ba-card">
              <div class="horizontal-ba">
                <!-- The before image is first -->
                  <?php 
                    $cleaning_business_aboutus_image1 = get_theme_mod('cleaning_business_aboutus_image1');

                    if(!empty($cleaning_business_aboutus_image1)){
                      echo '<img alt="'. esc_html(get_the_title()) .'" src="'.esc_url($cleaning_business_aboutus_image1).'" class="img-responsive secondry-bg-img" />';
                    }else{
                      echo '<img alt="cleaning_business_aboutus_image1" src="'.get_template_directory_uri().'/assets/images/abt3.jpg" class="img-responsive" />';
                    }
                  ?>
                  <?php 
                    $cleaning_business_aboutus_image2 = get_theme_mod('cleaning_business_aboutus_image2');

                    if(!empty($cleaning_business_aboutus_image2)){
                      echo '<img alt="'. esc_html(get_the_title()) .'" src="'.esc_url($cleaning_business_aboutus_image2).'" class="img-responsive secondry-bg-img" />';
                    }else{
                      echo '<img alt="cleaning_business_aboutus_image2" src="'.get_template_directory_uri().'/assets/images/abt2.jpg" class="img-responsive" />';
                    }
                  ?>
              </div>
            </div>
            <div class="about-circle1"></div>
            <div class="about-circle2"></div>
            <div class="about-circle3"></div>
          </div>
        </div>
      </div>
    </section>

  <?php }?>
  <?php do_action( 'cleaning_business_below_best_sellers' ); ?>
</main>
<?php get_footer(); ?>