<?php
$about_section = get_theme_mod( 'vw_book_store_pro_best_seller_enable' );

if ( 'Disable' == $about_section ) {
 return;
}
  $img_bg = get_theme_mod('vw_book_store_pro_best_seller_image_bg');
if( get_theme_mod('vw_book_store_pro_best_seller_bgcolor','') ) {
 $about_backg = 'background-color:'.esc_attr(get_theme_mod('vw_book_store_pro_best_seller_bgcolor','')).';';
}elseif( get_theme_mod('vw_book_store_pro_best_seller_bgimage','') ){
 $about_backg = 'background-image:url(\''.esc_url(get_theme_mod('vw_book_store_pro_best_seller_bgimage')).'\')';
}else{
 $about_backg = '';
}
if ( class_exists( 'WooCommerce' ) ) {
?>
<section id="best_seller" style="<?php echo esc_attr($about_backg); ?>" class="wow slideInUp delay-3000 animated <?php echo esc_attr($img_bg); ?>" data-wow-duration="2s">
  <div class="container">
    <div class="best_seller_title">
      <div class="row">
        <div class="col-lg-3 col-md-12 d-lg-flex align-items-center">
          <?php if(get_theme_mod('vw_book_store_pro_best_seller_title',true != '')){?>
              <h3><?php echo esc_html(get_theme_mod('vw_book_store_pro_best_seller_title')); ?></h3>
          <?php } ?>
        </div>
        <div class="col-lg-7 col-md-12 mt-md-3 mt-lg-3 d-lg-flex align-items-center">
          <ul class="nav-tabs nav justify-content-center" role="tablist">
            <?php $tab_count = get_theme_mod('vw_book_store_pro_tab_number', 5); 
            for($i=1; $i<= $tab_count; $i++ ) {?>
              <li class="nav-item">
                <a class="nav-link <?php if($i == 1){echo 'active';} ?>" href="#tab<?php echo esc_attr($i);?>" role="tab" data-bs-toggle="tab"><?php echo esc_html(get_theme_mod('vw_book_store_pro_slideproduct_tab1title'.$i,__('Trending Books','vw-book-store-pro'))); ?></a>
                <div class="divider"></div>
              </li>
            <?php }?>
          </ul>
        </div>
        <div class="col-lg-2 col-md-12">
          <?php if(get_theme_mod('vw_book_store_pro_best_seller_btn',true != '')){ ?>  
            <a href="<?php echo esc_url(get_theme_mod('vw_book_store_pro_best_seller_btn_link')); ?>"class="theme_green_button float-lg-right"><?php echo esc_html(get_theme_mod('vw_book_store_pro_best_seller_btn')); ?><i class="<?php echo esc_html(get_theme_mod('vw_book_store_pro_best_seller_btn_icon')); ?>"></i></a>
          <?php } ?>
        </div>
      </div>
    </div>
    <div class="tab-content">
      <!--tab 1 -->
      <?php $tab_count = get_theme_mod('vw_book_store_pro_tab_number', 5); 
        for($i=1; $i<= $tab_count; $i++ ) {?>
        <div role="tabpanel" class="tab-pane <?php if($i == 1){echo 'active';} ?>" id="tab<?php echo esc_attr($i);?>">
          <div class="row">
            <?php
            $args = array( 
            'post_type' => 'product', 
            'posts_per_page' => get_theme_mod('vw_book_store_pro_tab_category_products_limit'.$i),
            'product_cat' => get_theme_mod('vw_book_store_pro_cate_tab'.$i)
            );
            $loop = new WP_Query( $args );
            while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
            <div class="col-lg-3 col-md-6 col-sm-6 best_seller_col"> 
              <div class="inner_product product-content"> 
                <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); ?>">
                <div class="product-thumb">
                  <div class="product-sale "><?php woocommerce_show_product_sale_flash( $post, $product ); ?></div>
                  <?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()).'" alt="Placeholder" />'; ?>
                  <div class="custom-product-price"><?php echo $product->get_price_html(); ?></div>
                </div>
                <h5 class="product_head"><?php the_title(); ?></h5>
                <p><?php $excerpt = get_the_excerpt(); echo esc_html(vw_book_store_pro_string_limit_words($excerpt,8)); ?></p>        
                </a>
                <div class="custom_cart">
                  <?php if( $product->is_type( 'simple' ) ){ woocommerce_template_loop_add_to_cart( $loop->post, $product ); } ?>
                </div>
              </div>
            </div>
            <?php endwhile; ?>
            <?php wp_reset_query(); ?>
          </div>
        </div>
      <?php }?>
    </div>
  </div>
</section>
<?php }?>