<?php
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
use Magento\Framework\App\Action\Action;

// @codingStandardsIgnoreFile

?>
<?php
/**
 * Product list template
 *
 * @var $block \Magento\Catalog\Block\Product\ListProduct
 */
?>
<?php
$_productCollection = $block->getLoadedProductCollection();
$_helper = $this->helper('Magento\Catalog\Helper\Output');
$_aloHelper = $this->helper('Magiccart\Alothemes\Helper\Data');
?>
<div class="mage-magictabs mc-<?php echo $this->escapeHtml($this->getTypeFilter());?>">
<?php if (!$_productCollection->count()): ?>
    <div class="message info empty"><div><?php /* @escapeNotVerified */ echo __('We can\'t find products matching the selection.') ?></div></div>
<?php else: ?>
    <?php
        $viewMode = 'grid';
        $image = 'category_page_grid';
        $templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
    /**
     * Position for actions regarding image size changing in vde if needed
     */
    $pos = $block->getPositioned();
    ?>
    <?php 
        $config     = $this->getWidgetCfg(); 
        $timer       = $config['timer'];
        $showCart       = $config['cart'];
        $showCompare    = $config['compare'];
        $showWishlist   = $config['wishlist'];
        $showReview     = $config['review'];
		$swatchesRender = $block->getLayout()->createBlock('Magento\Swatches\Block\Product\Renderer\Listing\Configurable')->setTemplate('Magiccart_Magicproduct::product/listing/renderer.phtml');
    ?>
    <div class="products wrapper <?php /* @escapeNotVerified */ echo $viewMode; ?> products-<?php /* @escapeNotVerified */ echo $viewMode; ?>">
        <?php $iterator = 1; ?>
        <ol class="products list items product-items">
            <?php /** @var $_product \Magento\Catalog\Model\Product */ ?>
            <?php foreach ($_productCollection as $_product): ?>
                <?php /* @escapeNotVerified */ echo($iterator++ == 1) ? '<li class="item product product-item">' : '</li><li class="item product product-item">' ?>
                <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 // Product Image ?>
                    <div class="images-container">
                        <div class="product-hover">
                            <?php echo $_aloHelper->getLabels($_product); ?>
                            <?php echo $timer ? $_aloHelper->getTimer($_product) : ''; ?>
                            <a href="<?php /* @escapeNotVerified */ echo $_product->getProductUrl() ?>" class="product photo product-item-photo" tabindex="-1">
                                <?php echo $productImage->toHtml(); ?>
                            </a>
                        </div>
                        <?php if ($showWishlist || $showCompare || $showCart): ?>
                            <div class="actions-no hover-box">
                                 <a class="detail_links" href="<?php echo $_product->getProductUrl() ?>" ></a>
                                    <div class="product actions product-item-actions"<?php echo strpos($pos, $viewMode . '-actions') ? $position : ''; ?>>
                                            <?php if ($showCart): ?>
                                                <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]; ?>">
                                                            <?php echo $block->getBlockHtml('formkey')?>
                                                            <button type="submit"
                                                                    title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>"
                                                                    class="action tocart primary button btn-cart pull-left-none">
                                                                <span><i class="pe-7s-cart icons"></i><span><?php /* @escapeNotVerified */ echo __('Add to Cart') ?></span></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>
                                            <?php endif; ?>
                                            <?php if ($showWishlist || $showCompare): ?>
                                                <div data-role="add-to-links" class="actions-secondary add-to-links"<?php echo strpos($pos, $viewMode . '-secondary') ? $position : ''; ?>>
                                                    <?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow() && $showWishlist): ?>
                                                        <a href="#"
                                                           class="action towishlist"
                                                           title="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
                                                           aria-label="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
                                                           data-post='<?php /* @escapeNotVerified */ echo $block->getAddToWishlistParams($_product); ?>'
                                                           data-action="add-to-wishlist"
                                                           role="button">
                                                            <i class="icon-heart icons"></i><?php /* @escapeNotVerified */ echo __('Add to Wish List') ?>
                                                        </a>
                                                    <?php endif; ?>
                                                <?php if ($showCompare):
                                                        $compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');
                                                    ?>
                                                    <a href="#"
                                                       class="action tocompare"
                                                       title="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
                                                       aria-label="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
                                                       data-post='<?php /* @escapeNotVerified */ echo $compareHelper->getPostDataParams($_product); ?>'
                                                       role="button">
                                                        <i class="icon-bar-chart icons"></i><?php /* @escapeNotVerified */ echo __('Add to Compare') ?>
                                                    </a>
                                                <?php endif; ?>
                                                </div>
                                            <?php endif; ?>
                                    </div>
                            </div>
                        <?php endif; ?>
                    </div>
                    <div class="product details product-item-details products-textlink clearfix">
                        <?php
                            $_productNameStripped = $block->stripTags($_product->getName(), null, true);
                        ?>
                        <h2 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>
                        </h2>
                        <?php echo $showReview ? $block->getReviewsSummaryHtml($_product, $templateType) : ''; ?>
                        <?php /* @escapeNotVerified */ echo $block->getProductPrice($_product) ?>
                        <?php echo $swatchesRender->setProduct($_product)->toHtml() ?>
                        <?php echo $block->getProductDetailsHtml($_product); ?>
                    </div>
                </div>
                <?php echo($iterator == count($_productCollection)+1) ? '</li>' : '' ?>
            <?php endforeach; ?>
        </ol>
    </div>
    <?php if (!$block->isRedirectToCartEnabled()) : ?>
        <script type="text/x-magento-init">
        {
            "[data-role=tocart-form], .form.map.checkout": {
                "catalogAddToCart": {}
            }
        }
        </script>
    <?php endif; ?>
<?php endif; ?>
</div>
