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

if ( 'Disable' == $about_section ) {
 return;
}
$img_bg = get_theme_mod('vw_book_store_pro_category_image_attachment');
if( get_theme_mod('vw_book_store_pro_category_bgcolor','') ) {
 $about_backg = 'background-color:'.esc_attr(get_theme_mod('vw_book_store_pro_category_bgcolor','')).';';
}elseif( get_theme_mod('vw_book_store_pro_category_bgimage','') ){
 $about_backg = 'background-image:url(\''.esc_url(get_theme_mod('vw_book_store_pro_category_bgimage')).'\')';
}else{
 $about_backg = '';
}

if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
  $amp_class = 'col-lg-3 col-md-3 col-sm-6 col-12 mb-3';
  $amp_row = 'row';
}
else{
  $amp_class = '';
  $amp_row = '';
}

?>
<?php if ( class_exists( 'WooCommerce' ) ) {?>
  <section id="category" style="<?php echo esc_attr($about_backg); ?>" class="wow zoomIn delay-3000 animated <?php echo esc_attr($img_bg); ?>" data-wow-duration="2s">
    <div class="container" id="category">
      <div class="category-content">
        <div class="container">
          <?php if(get_theme_mod('vw_book_store_pro_category_title',true) != '' || get_theme_mod('vw_book_store_pro_category_btn',true) != ''){?>
            <div class="section-title d-inline-block w-100">
              <?php if(get_theme_mod('vw_book_store_pro_category_title',true) != ''){?>
                <h3 class="float-left align-self-end"><?php echo esc_html(get_theme_mod('vw_book_store_pro_category_title')); ?></h3>
              <?php } ?>

              <?php if(get_theme_mod('vw_book_store_pro_category_btn',true) != ''){ ?>  
                <a href="<?php echo esc_url(get_theme_mod('vw_book_store_pro_category_btn_link')); ?>"class="theme_green_button float-right"><?php echo esc_html(get_theme_mod('vw_book_store_pro_category_btn')); ?><i class="<?php echo esc_html(get_theme_mod('vw_book_store_pro_category_btn_icon')); ?>"></i></a>
              <?php } ?>
            </div> 
          <?php } ?>
          <div class="owl-carousel <?php echo esc_attr($amp_row); ?>">
            <?php
              $product_number = get_theme_mod('vw_book_store_pro_category_number');
              for($i =1; $i<=$product_number; $i++){
                if(get_theme_mod('vw_book_store_pro_product_cat'.$i,true) != '') {?>
                <div class="category_col <?php if($i == 1){ echo 'active';}?> <?php echo esc_attr($amp_class); ?>">
                  <div class="categorybox">
                    <?php
                      $var = get_term_by('slug', get_theme_mod('vw_book_store_pro_product_cat'.$i), 'product_cat');
                      $thumbnail_id = get_term_meta( $var->term_id, 'thumbnail_id', true );
                       $image = wp_get_attachment_url( $thumbnail_id ); 
                      echo "<img src='$image' alt=''/>";
                    ?>
                    <div class="categorybox-content">                      
                      <ul class="categoryicon">
                        <li><?php $link = get_term_link($var->term_id); ?>
                          <a href="<?php echo esc_url($link); ?>" class="fa fa-link"></a></li>
                      </ul>                    
                    </div>                  
                  </div>
                  <div>
                    <h4 class="categorytitle"><a href="<?php echo esc_url($link); ?>"><?php echo $var->name; ?></a></h4>
                    <p><?php echo $var->description;?> </p>
                  </div>
                </div>
                <?php } 
              } ?>
          </div>            
        </div>
      </div>
    </div>
  </section>
<?php } else {
 echo esc_html_e('Please Install Woocommerce to show the category section','vw-book-store-pro'); 
}?>