<?php 
	use Magento\Framework\App\Action\Action;
	
	$viewMode = 'grid';
	$image = 'category_page_grid';
	$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
	$_product = $this->getProduct();
	$_productNameStripped = $block->stripTags($_product->getName(), null, true);
	$productImage = $block->getImage($_product, $image);
	$_helper = $this->helper('Magento\Catalog\Helper\Output');
	$builderHelper = $this->helper('MGS\Fbuilder\Helper\Data');
	$hideName = $this->getData('hide_name');
	$hideReview = $this->getData('hide_review');
	$hidePrice = $this->getData('hide_price');
	$hideAddCart = $this->getData('hide_addcart');
	$hideAddWishlist = $this->getData('hide_addwishlist');
	$hideAddCompare = $this->getData('hide_addcompare');
	$hideDescription = $this->getData('hide_description');
	$themeSettingConfig = $this->helper('MGS\ThemeSettings\Helper\Config');
	
	$htmlStructure = $builderHelper->getStoreConfig('fbuilder/html_structure/single_product');
?>

<?php 
	
	// add to cart

	$aHelper = $this->Helper('MGS\AjaxCart\Helper\Data');
	$animationType = $aHelper->getConfig('ajaxcart/additional/animation_type');
	$animationType;

	$_animationTypeShowCart = false;
	if($animationType == 'showcart') {
		$_animationTypeShowCart = true;
	}

	$typeId = $_product->getTypeId();

	//echo $typeId;
	$redirectByTypeId = false;

	if($typeId == 'simple' || $typeId == 'virtual') {
		$redirectByTypeId = true;
	}

	$linkDetailProduct = $_product->getProductUrl();

?>


<div class="block widget mgs-product single-product products-grid product-items product-item">
<?php if(($_product && $_product->getId())): ?>
	<div class="product-item-info">
		<div class="product-top">
			<a href="<?= /* @escapeNotVerified */ $_product->getProductUrl() ?>" class="product photo product-item-photo" tabindex="-1">
				<?php echo $productImage->toHtml() ?>
			</a>
			<?php if($hidePrice!=1): ?>
				<div class="single-price">
					<?php echo $block->getProductPrice($_product) ?>
					 <?php 
						$percent = 0 - $themeSettingConfig->getPercent($_product);
						$configPercent = $themeSettingConfig->getConfigPercent();
					?>                      
					<?php if ($percent != 0 && $configPercent == 0): ?>						
						<div class="yousave">
							<span class="discount-percent">
								<?php echo $percent; ?>
								<span class="percent">%</span>
							</span>
						</div>
					<?php endif; ?>
				</div>
			<?php endif ?>
			<?php echo $themeSettingConfig->getProductLabel($_product); ?>
		</div>
		<div class="product-bottom">
			<div class="product details product-item-details">
				<div class="content-details">
					<?php if($hideName!=1): ?>
						<strong class="product name product-item-name">
							<a class="product-item-link"
							   href="<?php echo $_product->getProductUrl() ?>">
								<?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?>
							</a>
						</strong>
					<?php endif ?>
					
					<?php if($hideReview!=1): ?>
						<?php echo $block->getReviewsSummaryHtml($_product, $templateType, true) ?>
					<?php endif ?>
					
					<?php if ($hideDescription!=1):?>
						<div class="product description product-item-description">
							<?php $shortDescription = $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>
							<?php if($this->getData('truncate') && ($this->getData('truncate')>0)): ?>
								<?php $shortDescription = $builderHelper->truncateString(strip_tags($shortDescription), $this->getData('truncate')) ?>
							<?php endif ?>
							<?php echo $shortDescription ?>
						</div>
					<?php endif; ?>
					
					<?php if(($hideAddCart!=1) || ($hideAddWishlist!=1) ||($hideAddCompare!=1)): ?>
						<div class="product-item-inner">
							<div class="product actions product-item-actions">
								<?php if($hideAddCart!=1): ?>
									<?php if ($_product->isSaleable()): ?>
										<?php $postParams = $block->getAddToCartPostParams($_product); ?>
										<form data-role="tocart-form" data-product-sku="<?=  /* @NoEscape */ $_product->getSku() ?>" action="<?= /* @NoEscape */ $postParams['action'] ?>" method="post">
											<input type="hidden" name="product" value="<?= /* @escapeNotVerified */ $postParams['data']['product'] ?>">
											<input type="hidden" name="<?= /* @escapeNotVerified */ Action::PARAM_NAME_URL_ENCODED ?>" value="<?= /* @escapeNotVerified */ $postParams['data'][Action::PARAM_NAME_URL_ENCODED] ?>">
											<?= $block->getBlockHtml('formkey') ?>
											<?php if($_animationTypeShowCart == true && $redirectByTypeId == false){ ?>
												<button type="submit" title="<?= $block->escapeHtml(__('Add to Cart')) ?>" class="action tocart primary" onClick='window.location="<?php echo $linkDetailProduct; ?>"'>
													<span class="ti-shopping-cart">
														<span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
													</span>
												</button>
											<?php }else{?>
												<button type="submit" title="<?= $block->escapeHtml(__('Add to Cart')) ?>" class="action tocart primary tocart-item">
													<span class="ti-shopping-cart">
														<span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
													</span>
												</button>
											<?php } ?>
										</form>
									<?php else: ?>
										<?php if ($_product->isAvailable()): ?>
											<div class="stock available"><span><?= /* @escapeNotVerified */ __('In stock') ?></span></div>
										<?php else: ?>
											<div class="stock unavailable"><span><?= /* @escapeNotVerified */ __('Out of stock') ?></span></div>
										<?php endif; ?>
									<?php endif; ?>
								<?php endif ?>
								
								<?php if(($hideAddWishlist!=1) ||($hideAddCompare!=1)): ?>
									<div data-role="add-to-links" class="actions-secondary">
										<?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow() && ($hideAddWishlist!=1)): ?>
											<a href="#" class="action towishlist" title="<?= __('Add to Wish List') ?>" aria-label="<?= __('Add to Wish List') ?>" data-post='<?= /* @noEscape */ $block->getAddToWishlistParams($block->getProduct()) ?>' data-action="add-to-wishlist" role="button">
												<span class="ti-heart">
													<span><?php /* @escapeNotVerified */ echo __('Add to Wish List') ?></span>
												</span>
											</a>
										<?php endif; ?>
										<?php if($hideAddCompare!=1): ?>
											<?php $compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare'); ?>
											<a href="#" class="action tocompare" title="<?= $block->escapeHtml(__('Add to Compare')) ?>" aria-label="<?= $block->escapeHtml(__('Add to Compare')) ?>" data-post='<?= /* @escapeNotVerified */ $compareHelper->getPostDataParams($_product) ?>' role="button">
												<span class="ti-control-shuffle">  	
													<span><?php /* @escapeNotVerified */ echo __('Add to Compare') ?></span>
												</span>
											</a>
										<?php endif ?>
									</div>
								<?php endif ?>
							</div>
						</div>
					<?php endif ?>
				</div>
				
				<?php echo $this->getLayout()->createBlock('Magento\Swatches\Block\Product\Renderer\Listing\Configurable')->setProduct($_product)->setTemplate('Magento_Swatches::product/listing/renderer.phtml')->toHtml() ?>
				
				<?php //echo $block->getProductDetailsHtml($_product) ?>
			</div>
		</div>
	</div>
	<?php else: ?>
	<div class="message info empty"><div><?= /* @escapeNotVerified */ __('We can\'t find products matching the selection.') ?></div></div>
	<?php endif ?>

</div>