<?php
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php
/**
 * @var $block \Magento\Reports\Block\Product\Viewed
 */
?>
<?php
if ($exist = ($block->getRecentlyViewedProducts() && $block->getRecentlyViewedProducts()->getSize())) {
    $type = 'widget-viewed';
    $mode = 'list';

    $type = $type . '-' . $mode;

    $image = 'recently_viewed_products_images_names_widget';
    $title = __('Recently Viewed');
    $items = $block->getRecentlyViewedProducts();

    $showWishlist = false;
    $showCompare = false;
    $showCart = false;
    $rating = false;
    $description = false;
}
?>
<?php if ($exist): ?>
<div class="block widget block-viewed-products-<?php /* @escapeNotVerified */ echo $mode; ?>">
    <div class="block-title">
        <strong><?php /* @escapeNotVerified */ echo $title; ?></strong>
    </div>
    <div class="block-content">
        <?php $suffix = $block->getNameInLayout(); ?>
        <ol class="product-items" id="widget-viewed-<?php /* @escapeNotVerified */ echo $suffix; ?>">
            <?php $iterator = 1; ?>
            <?php foreach ($items as $_product): ?>
                <?php /* @escapeNotVerified */ echo($iterator++ == 1) ? '<li class="product-item">' : '</li><li class="product-item">' ?>
                <div class="product-item-info">
                    <a class="product-item-photo" href="<?php /* @escapeNotVerified */ echo $_product->getProductUrl() ?>"
                       title="<?php /* @escapeNotVerified */ echo $block->stripTags($_product->getName(), null, true) ?>">
                        <?php echo $block->getImage($_product, $image)->toHtml(); ?>
                    </a>
                    <div class="product-item-details">
                        <strong class="product-item-name">
                            <a href="<?php /* @escapeNotVerified */ echo $_product->getProductUrl() ?>"
                               title="<?php /* @escapeNotVerified */ echo $block->stripTags($_product->getName(), null, true) ?>"
                               class="product-item-link">
                                <?php /* @escapeNotVerified */ echo $this->helper('Magento\Catalog\Helper\Output')->productAttribute($_product, $_product->getName(), 'name') ?>
                            </a>
                        </strong>
                        <?php /* @escapeNotVerified */ echo $block->getProductPriceHtml(
                            $_product,
                            \Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE,
                            \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST,
                            [
                                'price_id_suffix' => '-widget-viewed-' . $suffix
                            ]
                        ) ?>
                        <div class="product-item-actions">
                            <?php if ($_product->isSaleable()): ?>
                            <div class="actions-primary">
                                <?php if ($_product->getTypeInstance()->hasRequiredOptions($_product)): ?>
                                    <button class="action tocart primary"
                                            data-mage-init='{"redirectUrl": {"url": "<?php /* @escapeNotVerified */ echo $block->getAddToCartUrl($_product) ?>"}}'
                                            type="button" title="<?php /* @escapeNotVerified */ echo __('Add to Cart') ?>">
                                        <span><?php /* @escapeNotVerified */ echo __('Add to Cart') ?></span>
                                    </button>
                                <?php else: ?>
                                    <?php
                                        $postDataHelper = $this->helper('Magento\Framework\Data\Helper\PostHelper');
                                        $postData = $postDataHelper->getPostData($block->getAddToCartUrl($_product), ['product' => $_product->getEntityId()]);
                                    ?>
                                    <button type="button" class="action tocart primary" data-post='<?php /* @escapeNotVerified */ echo $postData; ?>'>
                                        <span><?php /* @escapeNotVerified */ echo __('Add to Cart') ?></span>
                                    </button>
                                <?php endif; ?>
                            </div>
                            <?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>
                </div>
                <?php echo($iterator == count($items)+1) ? '</li>' : '' ?>
            <?php endforeach; ?>
        </ol>
    </div>
</div>
<?php endif; ?>
