<?php 
	$enable = $block->getConfig('enabled');
	if($enable < 1) return ; 
	$items = $block->getConfig('items');
	$speed = $block->getConfig('speed');
	$qty = $block->getConfig('qty');
	$showCart = $block->getShowAddtocart(); 
	$showWishlist = $block->getShowWishlist();
	$showCompare = $block->getShowCompare();
	$show_navigation = $block->getConfig('navigation');
	$show_pagination = $block->getConfig('pagination');
	$auto = $block->getConfig('auto');
	$rows = $block->getProductsOnRow();
	$itemsDefault = $block->getItemsDefault();
	$itemsDesktop = $block->getItemsDesktop();
	$itemsDesktopSmall = $block->getItemsDesktopSmall();
	$itemsTablet = $block->getItemsTablet();
	$itemsMobile = $block->getItemsMobile();
	$title = $block->getTitle(); 
	$identify = trim($block->getIdentify()); 
	$categoryIds = $block->getCategoryIds();
	$categoryIds = explode(',', $categoryIds);

	$productsOnRow = 2 ;
	if(!$productsOnRow) $productsOnRow = 3;

?>

<div class="categorytab-container">

	<header class='group-title1'>
		<?php 	echo '<h2>'.$title.'</h2>'; ?>
	</header>
	<div class="row">
		<div class="col-sm-3 col-xs-12">
			<ul class="tabs tabs<?php echo '-'.$identify;?>"> 
			   <?php 
				$k = 0;
				foreach($categoryIds as $cate_id) {
					$cate_model =  $block->getCategory($cate_id);
					$category = $cate_model->load($cate_id);
					$cateName = $category->getName();
					//echo "<pre>"; print_r($cate_model->getData()); die; 
					if($cateName) {
				?>
						<li class="<?php if($k==0){ echo "first"; }?>" rel="tab<?php echo $cate_id.'-'.$identify;?>"><a href="<?php echo $category->getUrl(); ?>"><?php  echo $cateName; ?></a></li>
				<?php }  $k++; } ?>
			</ul>
			<div class="static<?php echo '-'.$identify;?>">
				<?php echo $this->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('static_left_categorytabs')->toHtml();?>
			</div>
		</div>
		<?php 
			
			$imageBlock =  $block->getLayout()->createBlock('Magento\Catalog\Block\Product\Image');
			$image = 'new_products_content_widget_grid';
			$type = 'widget-new-grid';
			$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::DEFAULT_VIEW;
			
		?>
		<div class="col-sm-9 col-xs-12">
			<div class="tab_container"> 
				<?php //foreach($categoryIds as $cate_id) { 
					$cate_id = $categoryIds[0];
				?>
				<div id="tab<?php echo $cate_id.'-'.$identify;?>" class="tab_content_<?php echo $identify; ?>"> 
				<div class="owl-container">		
					<div class="category_tab_slider category-tab<?php echo '-'.$identify;?>  owl-carousel">
						<?php 
						$newItems =  $block -> getProductCate($cate_id)->getItems(); 
						$i=0;
						foreach($newItems as $_item) { 
							$productImage = $block->getImage($_item, $image);
						?>
						<?php if($i++%$rows==0) { ?> <div class="product_row"> <?php } ?>
							<div class="item">
								<div class="item-inner">
									
									<div class="image-container">
										<a href="<?php echo $block->getProductUrl($_item) ?>" class="product-item-photo">
											<?php echo $productImage->toHtml() ?>
										</a>
										<div class="actions">
										</div>
									</div>
									<div class="des">
										<div class="product-name">
											<strong class="product-item-name">
												<a title="<?php echo $block->escapeHtml($_item->getName()) ?>"
												   href="<?php echo $block->getProductUrl($_item) ?>"
												   class="product-item-link">
													<?php echo $block->escapeHtml($_item->getName()) ?>
												</a>
											</strong>
										</div>
										 
										 
										<?php if ($templateType): ?>
											<?php echo $block->getReviewsSummaryHtml($_item, $templateType,true); ?>
										<?php endif; ?>
										<?php
											echo $block->getProductPrice($_item);
										 ?>
										<div class="actions-second">
											<?php if ($showCart): ?>
												<div class="actions-primary">
													<?php if ($_item->isSaleable()): ?>
														<?php if ($_item->getTypeInstance()->hasRequiredOptions($_item)): ?>
															<button class="action tocart primary"
																	data-mage-init='{"redirectUrl":{"url":"<?php echo $block->getAddToCartUrl($_item) ?>"}}'
																	type="button" title="<?php echo __('Add to Cart') ?>">
																<span><?php echo __('Add to Cart') ?></span>
															</button>
														<?php else: ?>
															<?php
																$postDataHelper = $this->helper('Magento\Framework\Data\Helper\PostHelper');
																$postData = $postDataHelper->getPostData($block->getAddToCartUrl($_item), ['product' => $_item->getEntityId()])
															?>
															<button class="action tocart"
																	data-post='<?php echo $postData; ?>'
																	type="button" title="<?php echo __('Add to Cart') ?>">
																<span><?php echo __('Add to Cart') ?></span>
															</button>
														<?php endif; ?>
													<?php else: ?>
														<?php if ($_item->getIsSalable()): ?>
															<div class="stock available"><span><?php echo __('In stock') ?></span></div>
														<?php else: ?>
															<div class="stock unavailable"><span><?php echo __('Out of stock') ?></span></div>
														<?php endif; ?>
													<?php endif; ?>
												</div>
											<?php endif; ?>
											<?php if ($showWishlist || $showCompare): ?>
												<div class="actions-secondary add-to-links" data-role="add-to-links">
													<?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow() && $showWishlist): ?>
														<a href="#"
														   data-post='<?php echo $block->getAddToWishlistParams($_item); ?>'
														   class="action towishlist" data-action="add-to-wishlist"
														   title="<?php echo __('Add to Wishlist') ?>">
															<span><?php echo __('Add to Wishlist') ?></span>
														</a>
													<?php endif; ?>
													<?php if ($block->getAddToCompareUrl() && $showCompare): ?>
														<?php $compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');?>
														<a href="#" class="action tocompare"
														   data-post='<?php echo $compareHelper->getPostDataParams($_item);?>'
														   title="<?php echo __('Add to Compare') ?>">
															<span><?php echo __('Add to Compare') ?></span>
														</a>
													<?php endif; ?>
												</div>
											<?php endif; ?>
										</div>
									</div>
								</div>
							</div>
								<?php if($i%$rows==0 || $i == count($newItems)) { ?> </div> <?php }?>
						<?php 
						}
						?>
					</div>
				</div>	
					
				 </div><!-- #tab1 -->
				 <?php //}?>

				 
			</div> <!-- .tab_container --> 
		</div>
	</div>

</div>
<script type="text/javascript">
require([
  "jquery",
  "owlcarousel/minjs"
 ], function($,owlCarousel){

	// $(".tab_content_<?php echo $identify; ?>").hide();
	// $(".tab_content_<?php echo $identify; ?>:first").show(); 
	// $("ul.tabs<?php echo '-'.$identify;?> li").removeClass("active");
	$("ul.tabs<?php echo '-'.$identify;?> li.first").addClass("active");
	// $("ul.tabs<?php echo '-'.$identify;?> li").click(function() {
		// $("ul.tabs<?php echo '-'.$identify;?> li").removeClass("active");
		// $(this).addClass("active");
		// $(".tab_content_<?php echo $identify; ?>").hide();
		// var activeTab = $(this).attr("rel"); 
		// $("#"+activeTab).show(); 
	// });
	
	$(".category-tab<?php echo '-'.$identify;?>").owlCarousel({
	    items : <?php if($itemsDefault) echo $itemsDefault; else echo '6'; ?>,
		autoPlay : <?php if($auto) echo 'true'; else echo 'false'; ?>,
		slideSpeed : <?php if($speed) echo $speed; else echo '500'; ?>,
		navigation : <?php if($show_navigation) echo 'true'; else echo 'false'; ?>,
		stopOnHover : true,
		pagination : <?php if($show_pagination) echo 'true'; else echo 'false'; ?>,
		itemsDesktop : [1199,<?php if($itemsDesktop) echo $itemsDesktop; else echo '5'; ?>],
		itemsDesktopSmall : [992,<?php if($itemsDesktopSmall) echo $itemsDesktopSmall; else echo '3'; ?>],
		itemsTablet: [767,<?php if($itemsTablet) echo $itemsTablet; else echo '2'; ?>],
		itemsMobile : [479,<?php if($itemsMobile) echo $itemsMobile; else echo '1'; ?>],
		addClassActive : true,
		scrollPerPage:false
	});
	
});
 

</script> 
