<?php
/**
 *
 * SM Listing Tabs - Version 2.7.0
 * Copyright (c) 2017 YouTech Company. All Rights Reserved.
 * @license - Copyrighted Commercial Software
 * Author: YouTech Company
 * Websites: http://www.magentech.com
 */

use Magento\Framework\App\Action\Action;

if ($this->_isAjax()) {
	$products = $this->_ajaxLoad();
	$config = $this->_getConfig();
}else{
	$config = $this->getData('config');
	$products = $this->getData('products');
}
$_helper = $this->helper('Magento\Catalog\Helper\Output');
$viewMode = 'grid';
$image = 'category_page_grid';
$showDescription = false;
$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;

$type_loadmore = $config['type_show'] == 'loadmore' ? true : false;
$cls_mark = $type_loadmore ? ' ltabs-mark ' : '';
if (count($products)){
    /**
     * Position for actions regarding image size changing in vde if needed
     */
    $pos = 0;
if ($block->getPositioned()) {
    $pos = $block->getPositioned();
}
    ?>
    <div class="products wrapper <?php /* @escapeNotVerified */ echo $viewMode; ?> products-<?php /* @escapeNotVerified */ echo $viewMode; ?>">
        <?php $iterator = 1; ?>
        <ol class="products list items product-items  <?php echo $type_loadmore == false ? ' owl-carousel owl-theme' : ''; ?>"  <?php echo $type_loadmore ?  'data-liffect="fadeIn"' : '' ;?>>
            <?php /** @var $_product \Magento\Catalog\Model\Product */ ?>
            <?php foreach ($products as $_product):

			?>
                <?php /* @escapeNotVerified */ echo($iterator++ == 1) ? '<li class="item product product-item '.$cls_mark.'">' : '</li><li class="item product product-item '.$cls_mark.'">' ?>
                <div class="product-item-info" data-container="product-grid">
                    <?php
                    $productImage = $block->getImage($_product, $image);
                    if ($pos != null) {
                        $position = ' style="left:' . $productImage->getWidth() . 'px;'
                            . 'top:' . $productImage->getHeight() . 'px;"';
                    }
                    ?>
					<?php
					if ((int)$config['display_countdown'] && !empty($_product->getSpecialPrice()) && !empty($_product->getSpecialToDate())) {
						$specialToDate = $_product->getSpecialToDate();
					?>
					<div class="deals-countdown" data-timer="<?php echo date("Y/m/d H:i:s", strtotime($specialToDate)); ?>">
						<div class="deals-time time-day"><div class="num-time"></div><div class="title-time"></div></div>
						<div class="deals-time time-hours"><div class="num-time"></div><div class="title-time"></div></div>
						<div class="deals-time time-mins"><div class="num-time"></div><div class="title-time"></div></div>
						<div class="deals-time time-secs"><div class="num-time"></div><div class="title-time"></div></div>
					</div>
					<?php }?>
                    <?php // Product Image ?>
					<div class="image-product">
                    <a href="<?php /* @escapeNotVerified */ echo $_product->getProductUrl() ?>" class="product photo product-item-photo" tabindex="-1">
                        <?php echo $productImage->toHtml(); ?>
                    </a>
					</div>
                    <div class="product details product-item-details">
                        <?php
                            $_productNameStripped = $block->stripTags($_product->getName(), null, true);
                        ?>
                        <strong class="product name product-item-name">
                            <a class="product-item-link"
                               href="<?php /* @escapeNotVerified */ echo $_product->getProductUrl() ?>">
                                <?php /* @escapeNotVerified */ echo $_helper->productAttribute($_product, $_product->getName(), 'name'); ?>
                            </a>
                        </strong>
                        <?php echo $block->getReviewsSummaryHtml($_product, $templateType); ?>
                        <?php /* @escapeNotVerified */ echo $block->getProductPrice($_product) ?>
                        <?php echo $block->getProductDetailsHtml($_product); ?>

                        <div class="product-item-inner">
                            <div class="product actions product-item-actions"<?php echo strpos($pos, $viewMode . '-actions') ? $position : ''; ?>>
                                <div class="actions-primary"<?php echo strpos($pos, $viewMode . '-primary') ? $position : ''; ?>>
                                    <?php if ($_product->isSaleable()): ?>
                                        <?php $postParams = $block->getAddToCartPostParams($_product); ?>
                                        <form data-role="tocart-form" action="<?php /* @escapeNotVerified */ echo $postParams['action']; ?>" method="post">
                                            <input type="hidden" name="product" value="<?php /* @escapeNotVerified */ echo $postParams['data']['product']; ?>">
                                            <input type="hidden" name="<?php /* @escapeNotVerified */ echo Action::PARAM_NAME_URL_ENCODED; ?>" value="<?php /* @escapeNotVerified */ echo $postParams['data'][Action::PARAM_NAME_URL_ENCODED]; ?>">
											<input type="hidden" name="form_key" value="<?php echo $block->_getFormKey(); ?>" />
                                            <button type="submit"
                                                    title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>"
                                                    class="action tocart primary">
                                                <span><?php /* @escapeNotVerified */ echo __('Add to Cart') ?></span>
                                            </button>
                                        </form>
                                    <?php else: ?>
                                        <?php if ($_product->getIsSalable()): ?>
                                            <div class="stock available"><span><?php /* @escapeNotVerified */ echo __('In stock') ?></span></div>
                                        <?php else: ?>
                                            <div class="stock unavailable"><span><?php /* @escapeNotVerified */ echo __('Out of stock') ?></span></div>
                                        <?php endif; ?>
                                    <?php endif; ?>
                                </div>
                                <div data-role="add-to-links" class="actions-secondary"<?php echo strpos($pos, $viewMode . '-secondary') ? $position : ''; ?>>
                                    <?php if ($addToBlock = $block->getChildBlock('addto')): ?>
                                        <?php echo $addToBlock->setProduct($_product)->getChildHtml(); ?>
                                    <?php endif; ?>
                                </div>
                            </div>
                            <?php if ($showDescription):?>
                                <div class="product description product-item-description">
                                    <?php /* @escapeNotVerified */ echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>
                                    <a href="<?php /* @escapeNotVerified */ echo $_product->getProductUrl() ?>" title="<?php /* @escapeNotVerified */ echo $_productNameStripped ?>"
                                       class="action more"><?php /* @escapeNotVerified */ echo __('Learn More') ?></a>
                                </div>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
                <?php echo($iterator == count($products)+1) ? '</li>' : '' ?>
            <?php endforeach; ?>
        </ol>
    </div>
<?php
} else {
	  if (!$this->_isAjax()) { ?>
		 <div class="message info empty"><div><?php /* @escapeNotVerified */ echo __('We can\'t find products matching the selection.') ?></div></div>
<?php }
} ?>
