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

get_header(); ?>

<main id="skip-content">
  <section id="top-slider" slider-loop="<?php echo esc_html(get_theme_mod('pet_care_zone_slider_loop')); ?>">
    <?php if(get_theme_mod('pet_care_zone_top_slider_setting' ,true) != ''){ ?>
      <div class="slider-bg" style="background-image: url(<?php echo esc_url(get_theme_mod('cat_walking_slider_counter_background_image')); ?>)">
        <div class="slider-main-box">
          <div class="container">
          <?php $pet_care_zone_slide_pages = array();
            for ( $count = 1; $count <= 3; $count++ ) {
              $mod = intval( get_theme_mod( 'pet_care_zone_top_slider_page' . $count ));
              if ( 'page-none-selected' != $mod ) {
                $pet_care_zone_slide_pages[] = $mod;
              }
            }
              if( !empty($pet_care_zone_slide_pages) ) :
                $args = array(
                  'post_type' => 'page',
                  'post__in' => $pet_care_zone_slide_pages,
                  'orderby' => 'post__in'
                );
                $query = new WP_Query( $args );
                if ( $query->have_posts() ) :
                  $i = 1;
            ?>
              <div class="owl-carousel" role="listbox">
                <?php  while ( $query->have_posts() ) : $query->the_post(); ?>
                  <div class="slider-box-main">
                    <?php if(get_theme_mod('cat_walking_slider_button_text') != ''){ ?>
                      <div class="slide-btn mt-4">
                        <a href="<?php the_permalink(); ?>">
                          <?php echo esc_html(get_theme_mod('cat_walking_slider_button_text','')); ?>
                        </a>
                      </div>
                    <?php }?>
                    <div class="row">
                      <div class="col-lg-7 col-md-6 align-self-center position-relative">
                        <div class="slider-inner-main text-center ">
                          <?php if(get_theme_mod('pet_care_zone_slider_title_setting',1) == 1){ ?>
                            <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
                          <?php }?>
                          <?php if(get_theme_mod('cat_walking_slider_short_heading') != ''){ ?>
                            <h6 class="mb-2"><?php echo esc_html(get_theme_mod('cat_walking_slider_short_heading','')); ?></h6>
                          <?php }?>
                          <?php if(get_theme_mod('pet_care_zone_slider_content_setting',1) == 1){ ?>
                            <p><?php echo esc_html( wp_trim_words( get_the_content(), 30 )); ?></p>
                          <?php }?>
                        </div>
                      </div>
                      <div class="col-lg-5 col-md-6">
                        <?php if(has_post_thumbnail()){
                          the_post_thumbnail();
                          } else{?>
                          <img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/img/slider.png" alt="" />
                        <?php } ?>
                      </div>
                    </div>
                  </div>
                <?php $i++; endwhile;
                wp_reset_postdata();?>
              </div>
            <?php else : ?>
              <div class="no-postfound"></div>
            <?php endif;
          endif;?>
          <?php } ?>
        </div>
      </div>
      </div>
  </section>

  <?php if(get_theme_mod('cat_walking_about_us_setting',true) != ''){ ?>
   <section id="pet-about-us" class="py-5" style="background-image: url(<?php echo esc_url(get_theme_mod('cat_walking_about_us_background_image')); ?>)">
    <div class="container">
      <div class="row mt-5">
        <div class="col-lg-6 col-md-6 align-self-center about-us-content">
          <?php if(get_theme_mod('cat_walking_about_us_heading') != ''){ ?>
            <h4 class="mb-3"><?php echo esc_html(get_theme_mod('cat_walking_about_us_heading','')); ?></h4>
          <?php }?>
          <?php if(get_theme_mod('cat_walking_about_us_sub_heading') != ''){ ?>
            <h5 class="mb-3"><?php echo esc_html(get_theme_mod('cat_walking_about_us_sub_heading','')); ?></h5>
          <?php }?>
          <?php if(get_theme_mod('cat_walking_about_us_content') != ''){ ?>
            <p class="mb-2"><?php echo esc_html(get_theme_mod('cat_walking_about_us_content','')); ?></p>
          <?php }?>
          <?php if(get_theme_mod('cat_walking_about_btn_url') != '' || get_theme_mod('cat_walking_about_btn_text') != ''){ ?>
            <div class="about-btn mt-4">
              <a href="<?php echo esc_url(get_theme_mod('cat_walking_about_btn_url','')); ?>"><?php echo esc_html(get_theme_mod('cat_walking_about_btn_text','')); ?></a>
            </div>
          <?php }?>
        </div>
        <div class="col-lg-6 col-md-6 about-us-image my-5 pt-5 ">
          <?php if(get_theme_mod('cat_walking_about_us_left_image_1') != ''){ ?>
            <img class="about-image-1" src="<?php echo esc_url( get_theme_mod( 'cat_walking_about_us_left_image_1' )); ?>">
          <?php }?>
          <?php if(get_theme_mod('cat_walking_about_us_left_image_2') != ''){ ?>
            <img class="about-image-2" src="<?php echo esc_url( get_theme_mod( 'cat_walking_about_us_left_image_2' )); ?>">
          <?php }?>
          <?php if(get_theme_mod('cat_walking_about_us_left_image_3') != ''){ ?>
            <img class="about-image-3" src="<?php echo esc_url( get_theme_mod( 'cat_walking_about_us_left_image_3' )); ?>">
          <?php }?>
        </div>
      </div>
    </div>
  </section>
  <?php } ?>

<?php if(get_theme_mod('pet_care_zone_pet_product_setting') != ''){ ?>
   <section id="pet-product" class="py-5" product-loop="<?php echo esc_html(get_theme_mod('pet_care_zone_product_loop')); ?>">
    <div class="container">
      <div class="owl-carousel">
        <?php
        if ( class_exists( 'WooCommerce' ) ) {
          $args = array( 
            'post_type' => 'product',
            'posts_per_page' => get_theme_mod('pet_care_zone_pet_product_number'),
            'product_cat' => get_theme_mod('pet_care_zone_pet_product'),
            'order' => 'ASC'
          );
          $loop = new WP_Query( $args );
          while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
            <div class="product-box">
              <div class="product-image">
                <?php if (has_post_thumbnail( $loop->post->ID )) 
                    echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); 
                else 
                    echo '<img src="'.esc_url(wc_placeholder_img_src()).'" />'; 
                ?>
              </div>
              <div class="product-content">
                <h3><a href="<?php echo esc_url(get_permalink( $loop->post->ID )); ?>"><?php the_title(); ?></a></h3>
                <?php woocommerce_show_product_sale_flash( $post, $product ); ?>
                <p><?php echo esc_html( wp_trim_words( get_the_content(), 10 )); ?><p>
                <div class="addtocart my-4">
                  <?php if( $product->is_type( 'simple' ) ){ woocommerce_template_loop_add_to_cart( $loop->post, $product ); } ?>
                </div>
              </div>
            </div>
          <?php endwhile; wp_reset_query(); ?>
        <?php } ?>
      </div>
    </div>
  </section>
  <?php } ?>

  <section id="content-section" class="container">
    <?php
      if ( have_posts() ) : 
        while ( have_posts() ) : the_post();
          the_content();
        endwhile; 
      endif; 
    ?>
  </section>
</main>

<?php get_footer(); ?>