<?php
/**
 * Template Name: Custom Home Page
 */
get_header();

?>
<!-- banner section -->
<main id="maincontent" role="main">
  <?php 
  $reseller_store_number = get_theme_mod('reseller_store_slide_number');
  if($reseller_store_number != ''){
?>
  <?php if( get_theme_mod( 'reseller_store_slider_hide_show', true) == 1 || get_theme_mod( 'freseller_store_resp_slider_hide_show', true) == 1) { ?>
    <div class="container-fluid slide-container">
    <section id="slider" class="position-relative">
      <div id="carouselExampleIndicators" class="carousel slide <?php if ( get_theme_mod('reseller_store_slide_remove_fade',true) == 1 ) { ?> carousel-fade <?php } ?>" data-bs-ride="carousel" data-type="multi" data-interval="false">
        <div class="carousel-inner" role="listbox">
          <?php for ($reseller_store_i=1; $reseller_store_i<=$reseller_store_number; $reseller_store_i++) {?>
            <div <?php if($reseller_store_i == 1){echo 'class="carousel-item active"';} else{ echo 'class="carousel-item"';}?>>
                <?php if ( get_theme_mod('reseller_store_banner_background_image_sec',true) != "" ) {?>
                  <img class="slider-banner-img" src="<?php echo esc_url(get_theme_mod('reseller_store_banner_background_image_sec'.$reseller_store_i)); ?>" alt="<?php echo esc_attr(get_theme_mod('reseller_store_slide_title'.$reseller_store_i, true)); ?>" title="#slidecaption<?php echo esc_html($reseller_store_i); ?>">
                <?php } ?>
                <div class="carousel-caption">
                  <div class="inner_carousel">
                    <?php
                    $vw_reseller_store_tagline_title = get_theme_mod('reseller_store_tagline_title'.$reseller_store_i);
                    $vw_reseller_store_title_limit = 50; // Set your desired character limit here
                    if (!empty($vw_reseller_store_tagline_title)) { 
                        $vw_reseller_store_limited_title = vw_reseller_store_string_limit_characters($vw_reseller_store_tagline_title, $vw_reseller_store_title_limit);
                    ?>
                      <h2 class="slide_splice" id="dynamic-color" data-word="<?php echo esc_html(get_theme_mod('reseller_store_slider_heading_color_text')); ?>">
                          <?php echo esc_html($vw_reseller_store_limited_title); ?>
                      </h2>
                    <?php } ?>
                    <?php if ( get_theme_mod('reseller_store_slider_button_label1'.$reseller_store_i,'Start Exploring') != '' ) {?>
                      <div class ="slider-btn1">
                        <a href="<?php echo esc_url(get_theme_mod('reseller_store_slider_button_url1'.$reseller_store_i,false));?>"><?php echo esc_html(get_theme_mod('reseller_store_slider_button_label1'.$reseller_store_i,'Start Exploring'));?><span class="screen-reader-text"><?php esc_html_e( 'Start Exploring','reseller-store');?></span></a>
                      </div>
                    <?php }?>
                  </div>
                </div>
            </div>
          <?php } ?>
        </div>
        <?php if(get_theme_mod('reseller_store_slider_arrow_hide_show', true)){?>
          <button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleIndicators" id="prev" data-bs-slide="prev">
            <i class="<?php echo esc_attr(get_theme_mod('reseller_store_slider_prev_icon','fas fa-chevron-left')); ?>"></i>
          <span class="screen-reader-text"><?php echo esc_html('Previous','reseller-store'); ?></span>
          </button>
          <button class="carousel-control-next" type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide="next" id="next">
            <i class="<?php echo esc_attr(get_theme_mod('reseller_store_slider_next_icon','fas fa-chevron-right')); ?>"></i>
          <span class="screen-reader-text"><?php echo esc_html('Next','reseller-store'); ?></span>
          </button>
        <?php }?>
      </div>
      <div class="clearfix"></div>
    </div>
    </section>
  <?php }}?>
<?php do_action('reseller_store_after_banner'); ?>

  <!-- Product Section -->
<?php if(get_theme_mod('reseller_store_product_settings') != '') {?>
  <section id="main-product" class="py-5 wow bounceInRight delay-1000" data-wow-duration="3s"> 
    <div class="container">
      <div class="heding-title">
        <?php if( get_theme_mod('reseller_store_product_heading_product') != ''){ ?>
          <h2 class="text-center"><?php echo esc_html(get_theme_mod('reseller_store_product_heading_product'));?></h2>
        <?php }?>
        <?php if( get_theme_mod('reseller_store_product_title') != ''){ ?>
          <p class="text-center"><?php echo esc_html(get_theme_mod('reseller_store_product_title',''));?></p>
        <?php }?>
      </div> 
      <div class="owl-carousel"> 
        <?php if ( class_exists( 'WooCommerce' )) {?>
          <?php $args = array( 
            'post_type' => 'product',
            'product_cat' => get_theme_mod('reseller_store_product_settings'),
            'order' => 'ASC',
            'hide_empty' => 0,
          );
          $loop = new WP_Query( $args );
            while ( $loop->have_posts() ) : $loop->the_post(); global $product; 
              $reseller_store_start_date_ = get_post_meta( get_the_ID(), '_sale_price_dates_from', true);
              $reseller_store_end_date_ = get_post_meta( get_the_ID(), '_sale_price_dates_to', true);

             $reseller_store_end_date_final = '';
             if ($reseller_store_end_date_) {
               $reseller_store_end_date_final = date('Y-m-d', $reseller_store_end_date_);
             }
            ?>
            <div class="main-product-section position-relative">
              <h4 class="auction-timmer-name" data-date="<?php echo $reseller_store_end_date_final?>"></h4>
               <p class="the_timer"></p>
              <div class="box"> 
                <div class="social-img position-relative">  
                  <?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 class="socialbox">
                    <div class="share-btn-parent"><i class="fas fa-share-alt me-lg-1 share-i" aria-hidden="true"></i>
                    </div>
                      <ul class="show-icon">
                        <a class="twitter" href="https://twitter.com/share?url=<?php the_permalink(); ?>&amp;text=<?php the_title(); ?>" target="_blank"><i class="fab fa-twitter align-middle" aria-hidden="true"></i></a>
                        <a class="insta" href="https://www.instagram.com/sharer/sharer.php?u=<?php the_permalink();?>&amp;text=<?php the_title(); ?>" target="_blank"><i class="fab fa-instagram align-middle" aria-hidden="true"></i></a>
                        <a class="facebook" href="https://www.facebook.com/sharer/sharer.php?u=<?php the_permalink();?>&amp;text=<?php the_title(); ?>" target="_blank"><i class="fab fa-facebook-f align-middle " aria-hidden="true"></i></a>
                     </ul>
                  </div>
                </div>
                <div class="box-content">
                  <h3 class="text-center"><a href="<?php echo esc_url(get_permalink( $loop->post->ID )); ?>"><?php the_title(); ?></a></h3>
                  <p class="text-center <?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) ); ?>">
                    <span class="text-center product-text-selling"><?php echo esc_html(get_theme_mod('reseller_store_product_text',''));?></span>
                    <?php echo $product->get_price_html(); ?></p>
                  <a class="text-center pro-button" href="<?php the_permalink(); ?>"><?php echo esc_html('Buy Now','reseller-store');?><span class="screen-reader-text"><?php echo esc_html('Buy Now','reseller-store');?></span></a>
                </div>
              </div>
            </div>
          <?php endwhile; wp_reset_postdata(); ?> 
          <?php } ?> 
      </div>
    </div> 
  </section>
<?php }?>
<?php do_action( 'reseller_store_product_settings' ); ?>

<!-- product category -->
<?php if(get_theme_mod('reseller_store_show_hide_product_settings','true') != '') {?>
  <?php if ( class_exists( 'WooCommerce' ) ) : ?>
    <section id="category" class="">
      <div class="category-content">
        <?php
        // Initialize terms variable
        $reseller_store_terms = array();
        // Get the selected categories from the customizer
        $reseller_store_selected_category_ids = array();
        for ( $reseller_store_i = 1; $reseller_store_i <= 5; $reseller_store_i++ ) {
            $reseller_store_category_id = get_theme_mod( 'reseller_store_product_category_' . $reseller_store_i );
            if ( $reseller_store_category_id ) {
                $reseller_store_selected_category_ids[] = $reseller_store_category_id;
            }
        }
          if ( ! empty( $reseller_store_selected_category_ids ) ) {
              $reseller_store_terms = get_terms( array(
                  'taxonomy'   => 'product_cat',
                  'hide_empty' => false,
                  'include'    => $reseller_store_selected_category_ids,
                  'number'     => 5,
              ) );
          }
          if ( ! is_wp_error( $reseller_store_terms ) && ! empty( $reseller_store_terms ) ) {
              foreach ( $reseller_store_terms as $reseller_store_key => $reseller_store_term_value ) :
                  $reseller_store_items_text = 'reseller_store_category_additional_text' . ($reseller_store_key + 1);
                  ?>
                  <div class="categorybox-content position-relative">
                    <div class="cat-img-box">
                      <?php
                        $reseller_store_thumbnail_id = get_term_meta( $reseller_store_term_value->term_id, 'thumbnail_id', true );
                        $reseller_store_image = wp_get_attachment_url( $reseller_store_thumbnail_id );
                        if ( $reseller_store_image ) {
                          echo "<img src='{$reseller_store_image}' class='cat-image' alt='' width='100' height='100' />";
                        }
                      ?>
                    </div>
                    <div class="categorytitle">
                      <a href="<?php echo esc_attr( esc_url( get_term_link( $reseller_store_term_value->term_id ) ) ); ?>">
                          <?php echo esc_html( $reseller_store_term_value->name ); ?>
                      </a>
                      <p class="mb-0 count-para"><?php echo esc_html( $reseller_store_term_value->count ) . ' ' . esc_html(get_theme_mod( $reseller_store_items_text, false )); ?></p>
                      <div class="cat-main-div">
                      <a class="see-more-btn-category btn" href="<?php echo esc_attr( esc_url( get_category_link( $reseller_store_term_value->term_id ) ) ) ?>">
                        <?php echo esc_html(get_theme_mod('reseller_store_category_view_more_text','View More')); ?>
                      </a>
                    </div>
                    </div>
                  </div>
              <?php endforeach;
          } else {
              echo '<p class="text-center">' . esc_html('No categories found.') . '</p>';
          }
        ?>
      </div>
    </section>
  <?php else : ?>
      <p><?php esc_html_e( 'Please Install WooCommerce to show the category section', 'reseller-store' ); ?></p>
  <?php endif; ?>
<?php }?>

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

<?php get_footer(); ?> 