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

get_header(); ?>

<main id="maincontent" role="main">
  <?php do_action( 'christmas_holiday_before_slider' ); ?>

  <?php if( get_theme_mod( 'christmas_holiday_slider_hide_show', true) == 1 || get_theme_mod( 'christmas_holiday_resp_slider_hide_show', true) == 1) { ?>
    <section id="slider">
      <?php if(get_theme_mod('christmas_holiday_slider_type', 'Default slider') == 'Default slider' ){ ?>
      <div class="container">
        <div id="carouselExampleInterval" class="carousel slide" data-bs-ride="carousel" data-bs-interval="<?php echo esc_attr(get_theme_mod( 'christmas_holiday_slider_speed',4000)) ?>">
          <?php $christmas_holiday_sliders_page = array();
            for ( $count = 1; $count <= 3; $count++ ) {
              $mod = intval( get_theme_mod( 'christmas_holiday_slider_page' . $count ));
              if ( 'page-none-selected' != $mod ) {
                $christmas_holiday_sliders_page[] = $mod;
              }
            }
            if( !empty($christmas_holiday_sliders_page) ) :
              $args = array(
                'post_type' => 'page',
                'post__in' => $christmas_holiday_sliders_page,
                'orderby' => 'post__in'
              );
              $query = new WP_Query( $args );
              if ( $query->have_posts() ) :
                $i = 1;
          ?>
          <div class="carousel-inner" role="listbox">
            <?php while ( $query->have_posts() ) : $query->the_post(); ?>
              <div <?php if($i == 1){echo 'class="carousel-item active"';} else{ echo 'class="carousel-item"';}?>>
                <?php if(has_post_thumbnail()){
                  the_post_thumbnail();
                } else{?>
                  <img src="<?php echo esc_url(get_template_directory_uri()); ?>/inc/block-patterns/images/banner.png" alt="" />
                <?php } ?>
                <div class="carousel-caption">
                  <div class="inner_carousel">
                    <?php if (get_theme_mod('christmas_holiday_designation_small_text') != '') { ?>
                      <span class="slider-small-text"><?php echo esc_html(get_theme_mod('christmas_holiday_designation_small_text')) ?></span>
                    <?php } ?>
                    <h1 class="wow slideInRight delay-1000" data-wow-duration="2s"><a href="<?php echo esc_url( get_permalink() ); ?>" title="<?php echo the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
                    <p class="wow slideInRight delay-1000" data-wow-duration="2s"><?php $christmas_holiday_excerpt = get_the_excerpt(); echo esc_html( christmas_holiday_string_limit_words( $christmas_holiday_excerpt, esc_attr(get_theme_mod('christmas_holiday_slider_excerpt_number','15')))); ?></p>
                    <?php
                    $christmas_holiday_button_text = get_theme_mod('christmas_holiday_slider_button_text','Read More');
                    $christmas_holiday_button_link = get_theme_mod('christmas_holiday_top_button_url', '');
                    if (empty($christmas_holiday_button_link)) {
                      $christmas_holiday_button_link = get_permalink();
                    }
                    if ($christmas_holiday_button_text || !empty($christmas_holiday_button_link)) { ?>
                      <div class="slider-btn wow slideInRight delay-1000" data-wow-duration="2s">
                        <?php if( get_theme_mod('christmas_holiday_slider_button_text','Read More') != ''){ ?>
                          <a href="<?php echo esc_url($christmas_holiday_button_link); ?>" class="button redmor">
                          <?php echo esc_html($christmas_holiday_button_text); ?>
                            <span class="screen-reader-text"><?php echo esc_html($christmas_holiday_button_text); ?></span>
                          </a>
                        <?php } ?>
                      </div>
                    <?php }?>
                  </div>
                </div>
              </div>
            <?php $i++; endwhile;
            wp_reset_postdata();?>
          </div>
          <?php else : ?>
            <div class="no-postfound"></div>
          <?php endif;
          endif;?>
          <?php if(get_theme_mod('christmas_holiday_slider_arrow_hide_show', true)){?>
            <button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleInterval" id="prev" data-bs-slide="prev">
              <i class="<?php echo esc_attr(get_theme_mod('christmas_holiday_slider_prev_icon','fas fa-angle-left')); ?>"></i>
              <span class="screen-reader-text"><?php echo esc_html(__('Previous','christmas-holiday')); ?></span>
            </button>
            <button class="carousel-control-next" type="button" data-bs-target="#carouselExampleInterval" data-bs-slide="next" id="next">
              <i class="<?php echo esc_attr(get_theme_mod('christmas_holiday_slider_next_icon','fas fa-angle-right')); ?>"></i>
              <span class="screen-reader-text"><?php echo esc_html(__('Next','christmas-holiday')); ?></span>
            </button>
          <?php }?>
        </div>
      </div> 
      <div class="clearfix"></div>
      <?php } else if(get_theme_mod('christmas_holiday_slider_type', 'Advance slider') == 'Advance slider'){?>
          <?php echo do_shortcode(get_theme_mod('christmas_holiday_advance_slider_shortcode')); ?>
        <?php } ?>
    </section>
  <?php }?>

  <?php do_action( 'christmas_holiday_after_slider' ); ?>

  <?php if( get_theme_mod('christmas_holiday_bestseller_banner_page') != ''){ ?>
    <section id="best-seller-section" class="pt-5 px-2 wow bounceInDown delay-1000" data-wow-duration="3s">
      <div class="container">
        <div class="row">
          <div class="col-lg-3 col-md-4">
            <div class="sale-banner">
              <?php $christmas_holiday_bestseller_banner_pages = array();
                for ( $count = 0; $count <= 0; $count++ ) {
                  $mod = absint( get_theme_mod( 'christmas_holiday_bestseller_banner_page' ));
                  if ( 'page-none-selected' != $mod ) {
                    $christmas_holiday_bestseller_banner_pages[] = $mod;
                  }
                }
                if( !empty($christmas_holiday_bestseller_banner_pages) ) :
                  $args = array(
                    'post_type' => 'page',
                    'post__in' => $christmas_holiday_bestseller_banner_pages,
                    'orderby' => 'post__in'
                  );
                  $query = new WP_Query( $args );
                  if ( $query->have_posts() ) :
                    $i = 1;
              ?>
                <?php while ( $query->have_posts() ) : $query->the_post(); ?>
                    <div class="seller-banner-box" role="listbox">
                      <?php the_post_thumbnail(); ?>
                      <div class="seller-banner-content">
                        <?php if(get_theme_mod('christmas_holiday_product_timer_text1') != ''){?>
                          <p class="timer-text1"><?php echo esc_html(get_theme_mod('christmas_holiday_product_timer_text1')); ?></p>
                        <?php }?>
                        <h3 class="text-center wow zoomInDown delay-1000" data-wow-duration="2s"><a href="<?php echo esc_url( get_permalink() ); ?>" title="<?php echo the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
                        <p class="text-center wow zoomInDown delay-1000" data-wow-duration="2s"><?php $christmas_holiday_excerpt = get_the_excerpt(); echo esc_html( christmas_holiday_string_limit_words( $christmas_holiday_excerpt, esc_attr(get_theme_mod('christmas_holiday_slider_excerpt_number','10')))); ?></p>
                      </div>
                    </div>
                <?php $i++; endwhile;
                  wp_reset_postdata();?>
                <?php else : ?>
                  <div class="no-postfound"></div>
                <?php endif;
                endif;?>
            </div>
          </div>
          <div class="col-lg-9 col-md-8">
              <?php if ( class_exists( 'WooCommerce' ) && get_theme_mod('christmas_holiday_sale_product_category') != '' ) {?>
                <div class="sale-products">
                  <?php $args = array(
                    'post_type' => 'product',
                    'product_cat' => get_theme_mod('christmas_holiday_sale_product_category'),
                    'order' => 'ASC'
                  );
                  $loop = new WP_Query( $args );
                  while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
                    <div class="product-box position-relative">
                      <div class="row">
                        <div class="col-lg-6 col-md-12">
                          <h4><a href="<?php echo esc_url(get_permalink( $loop->post->ID )); ?>"><?php the_title(); ?></a></h4>
                          <p class="<?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) ); ?>"><?php echo $product->get_price_html(); ?></p>
                          <p class="box-content pt-2 pt-md-2 pt-lg-2"><?php $excerpt = get_the_excerpt(); echo esc_html( christmas_holiday_string_limit_words( $excerpt, esc_attr(get_theme_mod('christmas_holiday_services_excerpt_number','20')))); ?></p>
                          <div class="countdowntimer mt-2">
                            <?php if(get_theme_mod('christmas_holiday_product_timer_text') != ''){?>
                              <p class="timer-text mb-2"><?php echo esc_html(get_theme_mod('christmas_holiday_product_timer_text')); ?></p>
                            <?php }?>
                            <p id="timer" class="countdown">
                              <?php
                              $dateday = get_theme_mod('christmas_holiday_product_clock_timer_end'); ?>
                              <input type="hidden" class="date" value="<?php echo esc_html($dateday); ?>"></p>
                          </div>
                        </div>
                        <div class="col-lg-6 col-md-12">
                          <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(woocommerce_placeholder_img_src()).'" />'; ?>
                          </div>
                        </div>
                      </div>
                    </div>
                  <?php endwhile; wp_reset_query(); ?>
                </div>
              <?php } ?>
          </div>
        </div>
      </div>
    </section>
  <?php }?>

  <?php do_action( 'christmas_holiday_after_best_seller_product_section' ); ?>

  <div id="content-vw" class="entry-content py-3">
    <div class="container">
      <?php while ( have_posts() ) : the_post(); ?>
        <?php the_content(); ?>
      <?php endwhile; // end of the loop. ?>
    </div>
  </div>
</main>

<?php get_footer(); ?>
