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

get_header(); ?>

<main id="skip-content">
  <section id="top-slider" slider-loop="<?php echo esc_html(get_theme_mod('gardener_lite_slider_loop')); ?>">
    <?php if(get_theme_mod('gardener_lite_top_slider_setting') != ''){ ?>
    <?php $gardener_lite_slide_pages = array();
      for ( $gardener_lite_count = 1; $gardener_lite_count <= 3; $gardener_lite_count++ ) {
        $gardener_lite_mod = intval( get_theme_mod( 'gardener_lite_top_slider_page' . $gardener_lite_count ));
        if ( 'page-none-selected' != $gardener_lite_mod ) {
          $gardener_lite_slide_pages[] = $gardener_lite_mod;
        }
      }
      if( !empty($gardener_lite_slide_pages) ) :
        $gardener_lite_args = array(
          'post_type' => 'page',
          'post__in' => $gardener_lite_slide_pages,
          'orderby' => 'post__in'
        );
        $gardener_lite_query = new WP_Query( $gardener_lite_args );
        if ( $gardener_lite_query->have_posts() ) :
          $i = 1;
    ?>
    <div class="owl-carousel" role="listbox">
      <?php  while ( $gardener_lite_query->have_posts() ) : $gardener_lite_query->the_post(); ?>
        <div class="slider-box">
          <?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 class="slider-inner-box">
            <?php if(get_theme_mod('gardener_lite_slider_title_setting',1) == 1){ ?>
              <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
            <?php }?>
            <?php if(get_theme_mod('gardener_lite_slider_button_setting',1) == 1 && get_theme_mod('gardener_lite_slider_button_text','SHOP NOW') != ''){ ?>
              <div class="slider-box-btn mt-4">
                <a href="<?php the_permalink(); ?>"><?php esc_html_e(get_theme_mod('gardener_lite_slider_button_text','SHOP NOW')); ?></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('gardener_lite_new_product_setting',1) == 1){ ?>
  <section id="new-products" class="py-5">
    <div class="container">
      <?php if(get_theme_mod('gardener_lite_new_product_title') != ''){ ?>
        <h3 class="text-center"><?php echo esc_html(get_theme_mod('gardener_lite_new_product_title','')); ?></h3>
      <?php }?>
      <div class="row mt-4">
        <?php
        if ( class_exists( 'WooCommerce' ) ) {
          $gardener_lite_args = array(
            'post_type' => 'product',
            'posts_per_page' => get_theme_mod('gardener_lite_new_product_number'),
            'product_cat' => get_theme_mod('gardener_lite_new_product_category'),
            'order' => 'ASC'
          );
          $loop = new WP_Query( $gardener_lite_args );
          while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
            <div class="col-lg-3 col-md-4 col-sm-4">
              <div class="product-box mb-4">
                <div class="product-image">
                  <?php
                    if ( has_post_thumbnail( $loop->post->ID ) ) {
                        echo get_the_post_thumbnail( $loop->post->ID, 'woocommerce_thumbnail' );
                    } else {
                        echo '<img src="' . esc_url( wc_placeholder_img_src() ) . '" alt="' . esc_attr__( 'Placeholder', 'gardener-lite' ) . '" />';
                    }
                    ?>
                </div>
                <?php woocommerce_show_product_sale_flash( $post, $product ); ?>
                <div class="row p-2">
                  <div class="col-lg-7 col-md-7 col-sm-6">
                    <h4 class="mb-0"><a href="<?php echo esc_url(get_permalink( $loop->post->ID )); ?>"><?php the_title(); ?></a></h4>
                  </div>
                  <div class="col-lg-5 col-md-5 col-sm-6">
                    <p class="<?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) ); ?> mb-0"><?php echo $product->get_price_html(); ?></p>
                  </div>
                </div>
              </div>
            </div>
          <?php endwhile; wp_reset_query(); ?>
        <?php } ?>
      </div>
    </div>
  </section>
  <?php }?>

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

<?php get_footer(); ?>
