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

get_header(); ?>

<main id="skip-content">
  <section id="top-slider" >
    <?php $stylish_fashion_shop_slide_pages = array();
      for ( $stylish_fashion_shop_count = 1; $stylish_fashion_shop_count <= 3; $stylish_fashion_shop_count++ ) {
        $stylish_fashion_shop_mod = intval( get_theme_mod( 'stylish_fashion_shop_top_slider_page' . $stylish_fashion_shop_count ));
        if ( 'page-none-selected' != $stylish_fashion_shop_mod ) {
          $stylish_fashion_shop_slide_pages[] = $stylish_fashion_shop_mod;
        }
      }
      if( !empty($stylish_fashion_shop_slide_pages) ) :
        $stylish_fashion_shop_args = array(
          'post_type' => 'page',
          'post__in' => $stylish_fashion_shop_slide_pages,
          'orderby' => 'post__in'
        );
        $stylish_fashion_shop_query = new WP_Query( $stylish_fashion_shop_args );
        if ( $stylish_fashion_shop_query->have_posts() ) :
          $i = 1;
    ?>
    <div class="owl-carousel" role="listbox">
      <?php  while ( $stylish_fashion_shop_query->have_posts() ) : $stylish_fashion_shop_query->the_post(); ?>
        <div class="row slider-box">
          <div class="col-lg-2 col-md-0 "></div>
          <div class="col-lg-4 align-self-center">
            <div class="slider-inner-box">
              <?php if ( get_theme_mod('stylish_fashion_shop_slider_short_heading') != "" ) {?>
                <h2 class="mb-3"><?php echo esc_html(get_theme_mod('stylish_fashion_shop_slider_short_heading')); ?></h2>
              <?php }?>
              <h3 class="m-0"><?php the_title(); ?></h3>
              <div class="slide-btn mt-4"><a href="<?php the_permalink(); ?>"><?php esc_html_e('Shop Now','stylish-fashion-shop'); ?></a></div>
            </div>
          </div>
          <div class="col-lg-6 slider-image ps-0 align-self-center">
            <?php if ( get_theme_mod('stylish_fashion_shop_slider_small_image') != "" ) {?>
              <img class="small-img" src="<?php echo esc_url(get_theme_mod('stylish_fashion_shop_slider_small_image')); ?>" alt="small image">
            <?php }?>
            <?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>
      <?php $i++; endwhile;
      wp_reset_postdata();?>
    </div>
    <?php else : ?>
      <div class="no-postfound"></div>
    <?php endif;
    endif;?>
  </section>

  <section id="best-sell" class=" py-5">
    <div class="container">
      <div class="heading mb-3 text-center">
        <?php if ( get_theme_mod('stylish_fashion_shop_best_sells_section_heading') != "" ) {?>
          <h3 class="main_heading m-0"><?php echo esc_html(get_theme_mod('stylish_fashion_shop_best_sells_section_heading')); ?>
          </h3>
        <?php }?>
      </div>
      <?php if(class_exists('woocommerce')){ ?>
       <div class="owl-carousel">
          <?php 
             $args = array(
              'post_type' => 'product',
              'product_cat' =>  get_theme_mod('stylish_fashion_shop_cate_tab'),
              'orderby' =>'date','order' => 'DESC' );
             $loop = new WP_Query( $args );           
             while ( $loop->have_posts() ){
             $loop->the_post(); 
             global $product; ?>
            <div class="sells-product">
              <div class="prodimg_box">
                <a href="<?php echo esc_url(get_permalink( $loop->post->ID )); ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">
                <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'our_product'); else echo '<img src="'.esc_url(wc_placeholder_img_src()).'" alt="Placeholder" width="300px" height="300px" />'; ?>
                </a>
                <span class="discount_amt">
                  <?php $percentages = stylish_fashion_shop_woocommerce_get_product_sale_percentages( $product );
                    $label       = stylish_fashion_shop_woocommerce_get_product_sale_percentage_label( $percentages, '' );
                    echo $label;
                  ?><?php esc_html_e(' OFF','stylish-fashion-shop'); ?> 
                </span>
              </div>
              <div class="text_box">
                <div class="rating">
                  <?php if( $product->is_type( 'simple' ) ){ woocommerce_template_loop_rating( $loop->post, $product ); } ?>
                  <p class="m-0 <?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) ); ?>"><?php echo $product->get_price_html(); ?></p>
                </div>
                <span class="woo-cat"><?php echo wc_get_product_category_list( $product->get_id(),); ?></span>
                <h4 class="hidedesktop p-0 mb-3 mt-1"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                <div class="btn-box">
                  <span class="sale_cart text-start">
                    <?php if( $product->is_type( 'simple' ) ){ woocommerce_template_loop_add_to_cart( $loop->post, $product ); } ?>
                  </span>
                  <?php if(class_exists('YITH_WCWL')){ ?>
                    <span class="wishlist"><?php echo do_shortcode('[yith_wcwl_add_to_wishlist]'); ?></span>
                  <?php }?>
                </div>
              </div>
            </div>
          <?php  } wp_reset_query(); ?>
       </div>
      <?php }?>
    </div>
  </section>
  <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(); ?>