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

get_header(); ?>

<main id="skip-content">
  <section id="top-slider">
    <?php $royal_jewellery_slide_pages = array();
      for ( $royal_jewellery_count = 1; $royal_jewellery_count <= 3; $royal_jewellery_count++ ) {
        $royal_jewellery_mod = intval( get_theme_mod( 'royal_jewellery_top_slider_page' . $royal_jewellery_count ));
        if ( 'page-none-selected' != $royal_jewellery_mod ) {
          $royal_jewellery_slide_pages[] = $royal_jewellery_mod;
        }
      }
      if( !empty($royal_jewellery_slide_pages) ) :
        $royal_jewellery_args = array(
          'post_type' => 'page',
          'post__in' => $royal_jewellery_slide_pages,
          'orderby' => 'post__in'
        );
        $royal_jewellery_query = new WP_Query( $royal_jewellery_args );
        if ( $royal_jewellery_query->have_posts() ) :
          $i = 1;
    ?>
    <div class="owl-carousel" role="listbox">
      <?php  while ( $royal_jewellery_query->have_posts() ) : $royal_jewellery_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/images/slider.png" alt="" />
          <?php } ?>
          <div class="slider-inner-box">
            <p class="content mb-4"><?php echo esc_html( wp_trim_words( get_the_content(), esc_attr(get_theme_mod('royal_jewellery_slider_excerpt_length', 5)) )); ?></p>
            <h2 class="m-0"><?php the_title(); ?></h2>
            <div class="slide-btn mt-5"><a href="<?php the_permalink(); ?>"><?php esc_html_e('Shop Now','royal-jewellery'); ?></a></div>
          </div>
        </div>
      <?php $i++; endwhile;
      wp_reset_postdata();?>
    </div>
    <?php else : ?>
      <div class="no-postfound"></div>
    <?php endif;
    endif;?>
  </section>
  <section class="product-sec py-5 ">
    <div class="container">
      <div class="row">
        <div class="col-lg-6 col-md-6 col-sm-6 col-12 product-img text-right align-self-center">
          <?php if(get_theme_mod('royal_jewellery_product_image') != ''){ ?>
            <img src="<?php echo esc_url(get_theme_mod('royal_jewellery_product_image')); ?>">
          <?php }?>
        </div>
        <div class="col-lg-6 col-md-6 col-sm-6 col-12 align-self-center">
          <div class="row text-center headings">
            <div class="col-lg-8 col-md-12 col-sm-12 col-12">
              <?php if(get_theme_mod('royal_jewellery_product_main_heading') != ''){ ?>
                <h3 class="mb-2"><?php echo esc_html(get_theme_mod('royal_jewellery_product_main_heading','')); ?></h3>
              <?php }?>
              <?php if(get_theme_mod('royal_jewellery_product_main_discription') != ''){ ?>
                <p><?php echo esc_html(get_theme_mod('royal_jewellery_product_main_discription','')); ?></p>
              <?php }?>
            </div>
            <div class="col-lg-4 col-md-12 col-sm-12 col-12 text-lg-right">
              <?php if(get_theme_mod('royal_jewellery_product_main_button_url') != '' || get_theme_mod('royal_jewellery_product_main_button_text') != '' ){ ?>
                <div class="product-btn mt-4"><a href="<?php echo esc_url(get_theme_mod('royal_jewellery_product_main_button_url','')); ?>"><?php echo esc_html(get_theme_mod('royal_jewellery_product_main_button_text','')); ?></a></div>
                </div>
              <?php }?>
          </div>
          <div class="owl-carousel product-home-box">
            <?php
            if ( class_exists( 'WooCommerce' ) ) {
              $royal_jewellery_args = array(
                'post_type' => 'product',
                'posts_per_page' => get_theme_mod('royal_jewellery_home_product_per_page', 2),
                'product_cat' => get_theme_mod('royal_jewellery_home_product'),
                'order' => 'ASC'
              );
              $loop = new WP_Query( $royal_jewellery_args );
              while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
                <div class="products-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()).'" />'; ?>
                    <?php if(class_exists('YITH_WCWL')){ ?>
                        <span class="wishlist"><?php echo do_shortcode('[yith_wcwl_add_to_wishlist]'); ?></span>
                    <?php }?>
                  </div>
                  <div class="product-content text-center pt-3">
                    <span class="woo-cat"><?php echo wc_get_product_category_list( $product->get_id(),); ?></span>
                    <h3><a href="<?php echo esc_url(get_permalink( $loop->post->ID )); ?>"><?php the_title(); ?></a></h3>
                    <p class="<?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) ); ?> m-0"><?php echo $product->get_price_html(); ?></p>
                    <div class="rating mb-4 mt-2">
                      <?php if( $product->is_type( 'simple' ) ){ woocommerce_template_loop_rating( $loop->post, $product ); } ?>
                    </div>
                    <div class="pro-button mt-3">
                      <span class="me-1"><?php if( $product->is_type( 'simple' ) ){ woocommerce_template_loop_add_to_cart( $loop->post, $product ); } ?></span>
                      <?php if(class_exists('YITH_WCQV')){ ?>
                        <span class=""><?php echo do_shortcode('[yith_quick_view]'); ?></span>
                      <?php }?>
                    </div>
                  </div>
                </div>
              <?php endwhile; wp_reset_query(); ?>
            <?php } ?>
          </div>
        </div>
      </div>
    </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(); ?>