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

// @codingStandardsIgnoreFile

?>
<?php
if ($exist = $block->getRecentlyComparedProducts()) {
    $type = 'widget-compared';
    $mode = 'list';

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

    $image = 'recently_compared_products_images_names_widget';
    $title = __('Recently Compared');
    $items = $exist;

    $showWishlist = false;
    $showCompare = false;
    $showCart = false;
    $rating = false;
    $description = false;
}
?>
<?php if ($exist): ?>
<div class="block widget block-compared-products-<?= /* @escapeNotVerified */ $mode ?>">
    <div class="block-title">
        <strong><?= /* @escapeNotVerified */ $title ?></strong>
    </div>
    <div class="block-content">
        <?php $suffix = $block->getNameInLayout(); ?>
        <ol class="product-items" id="widget-compared-<?= /* @escapeNotVerified */ $suffix ?>">
            <?php foreach ($items as $_product): ?>
                <li class="product-item">
                    <div class="product-item-info">
                        <a class="product-item-photo" href="<?= /* @escapeNotVerified */ $_product->getProductUrl() ?>"
                           title="<?= /* @escapeNotVerified */ $block->stripTags($_product->getName(), null, true) ?>">
                            <?= $block->getImage($_product, $image)->toHtml() ?>
                        </a>
                        <div class="product-item-details">
                            <strong class="product-item-name">
                                <a href="<?= /* @escapeNotVerified */ $_product->getProductUrl() ?>"
                                   title="<?= /* @escapeNotVerified */ $block->stripTags($_product->getName(), null, true) ?>)">
                                    <?= /* @escapeNotVerified */ $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-compared-' . $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": "<?= /* @escapeNotVerified */ $block->getAddToCartUrl($_product) ?>"}}'
                                            type="button" title="<?= /* @escapeNotVerified */ __('Add to Cart') ?>">
                                        <span><?= /* @escapeNotVerified */ __('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 class="action tocart primary"
                                            data-post='<?= /* @escapeNotVerified */ $postData ?>'
                                            type="button" title="<?= /* @escapeNotVerified */ __('Add to Cart') ?>">
                                        <span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
                                    </button>
                                <?php endif; ?>
                                </div>
                            <?php else: ?>
                                <?php if ($_product->getIsSalable()): ?>
                                    <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; ?>
                            </div>
                        </div>
                    </div>
                </li>
            <?php endforeach; ?>
        </ol>
    </div>
</div>
<?php endif; ?>
