<?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');
	$configHelper = $this->helper('MGS\ThemeSettings\Helper\Config');
	$hideName = $this->getData('hide_name');
	$hideReview = $this->getData('hide_review');
	$hidePrice = $this->getData('hide_price');
	$hideAddCart = $this->getData('hide_addcart');
	$hideAddCompare = $this->getData('hide_addcompare');
	$hideDescription = $this->getData('hide_description');
	$templateStyle = $this->getData('style-template');
	$blockData =  array(
		"fbuilder_days" => $this->getData('fbuilder_days'),
		"fbuilder_hours" => $this->getData('fbuilder_hours'),
		"fbuilder_minutes" => $this->getData('fbuilder_minutes'),
		"fbuilder_seconds" => $this->getData('fbuilder_seconds')
	);
?>
<?php if($_product->getId()): ?>
<div class="block widget mgs-product single-deal products-grid product-items product-item">
	<div class="product-item-info template-<?=$templateStyle;?>">
		<div class="product details product-item-details">
			<?php if($this->getData('sub_title')): ?><div class="sub-title"><?= $this->getData('sub_title'); ?></div><?php endif ?>
			<?php if($hideName!=1): ?>
				<h2 class="product name product-item-name">
					<a class="product-item-link"
					   href="<?= $_product->getProductUrl() ?>">
						<?= $_helper->productAttribute($_product, $_product->getName(), 'name') ?>
					</a>
				</h2>
			<?php endif ?>
			
			<?php if($templateStyle==2): ?>
				<?php if($hidePrice!=1): ?>
					<?= $block->getProductPrice($_product) ?>
				<?php endif ?>
			<?php endif ?>	
				
			<?php if($hideReview!=1): ?>
				<?= $block->getReviewsSummaryHtml($_product, $templateType, true) ?>
			<?php endif ?>
			
			<?php if ($hideDescription!=1):?>
				<?php $shortDescription = $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>
				<?php if($this->getData('truncate') && ($this->getData('truncate')>0)): ?>
					<?php $shortDescription = $configHelper->truncateString(strip_tags($shortDescription), $this->getData('truncate')) ?>
				<?php endif ?>
				<?php if($shortDescription): ?>
					<div class="product description product-item-description">
						<?= $shortDescription ?>
					</div>
				<?php endif ?>
			<?php endif; ?>
			
			<?php if($templateStyle==1): ?>
				<?php if($hidePrice!=1): ?>
					<?= $block->getProductPrice($_product) ?>
				<?php endif ?>
			<?php endif ?>
			
			<?php if($templateStyle==1): ?>
			<div class="product-info-label">
				<div class="save-count"><?= __('Save %1%', $configHelper->getPercent($_product)) ?></div>
				<?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; ?>
			</div>
			<?php endif ?>
			
			<?= $this->getLayout()->createBlock('MGS\Fbuilder\Block\Products\Deals')->setProduct($_product)->setTemplate('MGS_Fbuilder::products/deals/time.phtml')->setBlockData($blockData)->toHtml() ?>
			
			<?php if(($hideAddCart!=1)): ?>
				<div class="product-item-inner">
					<div class="product actions product-item-actions">
						<div class="actions-primary">
							<?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') ?>
									<button type="submit" title="<?= $block->escapeHtml(__('Add to Cart')) ?>" class="action tocart default">
										<span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
									</button>
								</form>
							<?php endif; ?>
						</div>
					</div>
				</div>
			<?php else: ?>
				<div class="product-item-inner">
					<a href="<?= $_product->getProductUrl() ?>" title="<?= $block->escapeHtml(__('Shop Now')) ?>" class="action <?php if($templateStyle==2): ?> btn-radius btn-blue <?php else:?> default <?php endif; ?>">
						<span><?= /* @escapeNotVerified */ __('Shop Now') ?></span>
					</a>
				</div>
			<?php endif ?>
		</div>
	</div>
</div>
<?php else: ?>
	<div class="message info empty">
		<div><?= /* @escapeNotVerified */ __('There are no products matching the selection.') ?></div>
	</div>
<?php endif ?>