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

get_header(); ?>

<main id="skip-content">
  <section id="top-slider">
    <?php if(get_theme_mod('kids_online_store_slider_setting',true) != ''){ ?>
    <?php $kids_online_store_slide_pages = array();
      for ( $kids_gift_shop_count = 1; $kids_gift_shop_count <= 3; $kids_gift_shop_count++ ) {
        $kids_gift_shop_mod = intval( get_theme_mod( 'kids_online_store_top_slider_page' . $kids_gift_shop_count ));
        if ( 'page-none-selected' != $kids_gift_shop_mod ) {
          $kids_online_store_slide_pages[] = $kids_gift_shop_mod;
        }
      }
      if( !empty($kids_online_store_slide_pages) ) :
        $kids_gift_shop_args = array(
          'post_type' => 'page',
          'post__in' => $kids_online_store_slide_pages,
          'orderby' => 'post__in'
        );
        $kids_gift_shop_query = new WP_Query( $kids_gift_shop_args );
        if ( $kids_gift_shop_query->have_posts() ) :
          $i = 1;
    ?>
    <div class="owl-carousel" role="listbox">
      <?php  while ( $kids_gift_shop_query->have_posts() ) : $kids_gift_shop_query->the_post(); ?>
        <div class="slider-box">
          <?php if(has_post_thumbnail()){
            the_post_thumbnail();
            } else{?>
            <img src="<?php echo esc_url(get_theme_file_uri()); ?>/assets/img/slider.png" alt="" />
          <?php } ?>
          <div class="slider-inner-box">
            <?php if(get_theme_mod('kids_online_store_slider_title_setting',1) == 1){ ?>
              <h2><?php the_title(); ?></h2>
            <?php }?>
            <?php if(get_theme_mod('kids_online_store_slider_content_setting',1) == 1){ ?>
              <p class="mb-4"><?php $kids_online_store_excerpt = get_the_excerpt(); echo esc_html( kids_online_store_string_limit_words( $kids_online_store_excerpt, esc_attr(get_theme_mod('kids_online_store_slider_excerpt_length', 40)) ) ); ?></p>
            <?php }?>
            <?php if(get_theme_mod('kids_online_store_slider_button_setting',1) == 1 && get_theme_mod('kids_online_store_slider_button_text','Book Online') != ''){ ?>
              <div class="slide-btn"><a href="<?php the_permalink(); ?>"><?php esc_html_e(get_theme_mod('kids_online_store_slider_button_text','Book Online')); ?></a></div>
            <?php }?>
          </div>
        </div>
      <?php $i++; endwhile;
      wp_reset_postdata();?>
    </div>
    <?php else : ?>
      <div class="no-postfound"></div>
    <?php endif;
    endif;?>
    <?php } ?>
  </section>

<?php if(get_theme_mod('kids_gift_shop_services_setting',true) != ''){ ?>
  <section id="services-topic" class="py-5">
    <div class="container">
      <?php if(get_theme_mod('kids_gift_shop_services_category_title') != ''){ ?>
        <h3 class="mb-5 text-center "><?php echo esc_html(get_theme_mod('kids_gift_shop_services_category_title','')); ?></h3>
      <?php }?>
      <div class="row">
        <?php
          $kids_gift_shop_catData = get_theme_mod('kids_gift_shop_menu_items','');
          if($kids_gift_shop_catData){
            $kids_gift_shop_page_query = new WP_Query(array( 'category_name' => esc_html($kids_gift_shop_catData,'kids-gift-shop')));
            while( $kids_gift_shop_page_query->have_posts() ) : $kids_gift_shop_page_query->the_post(); ?>
              <div class="col-lg-4 col-md-6 col-sm-6">
                <div class="box mb-4">
                  <?php if(has_post_thumbnail()){
                    the_post_thumbnail();
                    } else{?>
                    <img src="<?php echo esc_url(get_theme_file_uri()); ?>/assets/img/service.png" alt="" />
                  <?php } ?>
                  <div class="box-cont">
                    <h3 class="mt-2"><?php the_title(); ?></h3>
                    <p><?php $kids_gift_shop_excerpt = get_the_excerpt(); echo esc_html( kids_online_store_string_limit_words( $kids_gift_shop_excerpt, 10 )); ?></p>
                  </div>
                  <div class="box-content">
                    <h3 class="mt-2"><?php the_title(); ?></h3>
                    <p><?php $kids_gift_shop_excerpt = get_the_excerpt(); echo esc_html( kids_online_store_string_limit_words( $kids_gift_shop_excerpt, 10 )); ?></p>
                    <div class="slide-btn">
                      <a href="<?php the_permalink(); ?>"><?php esc_html_e('Book Now','kids-gift-shop'); ?></a>
                    </div>
                  </div>
                </div>
              </div>
            <?php endwhile;
            wp_reset_postdata();
          } ?>
      </div>
    </div>
  </section>
<?php } ?>

<?php if(get_theme_mod('kids_online_store_product_setting') != ''){ ?>
    <section id="homepage-product">
    <div class="container">
      <div class="row product-home-box">
        <?php
        if ( class_exists( 'WooCommerce' ) ) {
          $kids_online_store_args = array(
          'post_type' => 'product',
          'posts_per_page' => get_theme_mod('kids_online_store_home_product_number'),
          'product_cat' => get_theme_mod('kids_online_store_home_product'),
          'order' => 'ASC'
          );
          $loop = new WP_Query( $kids_online_store_args );
          while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
            <div class="col-lg-3 col-md-4 col-sm-6">
              <div class="product-box">
                <div class="product-image">
                  <span class="product-sale-tag">
                    <?php woocommerce_show_product_sale_flash( $post, $product ); ?>
                  </span>
                  <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.esc_url(woocommerce_placeholder_img_src()).'" />'; ?>
                </div>
                <h4><a href="<?php echo esc_url(get_permalink( $loop->post->ID )); ?>">
                  <?php the_title(); ?><span class="screen-reader-text"><?php echo esc_html('best-seller-content', 'kids-online-store' ) ; ?></span>
                </a></h4>
                <p class="price"><?php echo $product->get_price_html(); ?></p>
              </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(); ?>
