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

/**
 * @deprecated
 */

/** @var \Magento\Catalog\Block\Product\Compare\ListCompare $block */
if ($exist = $block->getRecentlyComparedProducts()) {
    $type = 'widget-compared';
    $mode = 'grid';

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

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

    $showWishlist = true;
    $showCompare = true;
    $showCart = true;
    $rating = 'short';
    $description = ($mode == 'list') ? true : false;
}
?>

<?php if ($exist) : ?>
    <div class="block widget block-compared-products-<?= $block->escapeHtmlAttr($mode) ?>">
        <div class="block-title">
            <strong role="heading" aria-level="2"><?= $block->escapeHtml($title) ?></strong>
        </div>
        <div class="block-content">
            <?= '<!-- ' . $block->escapeHtml($image) . '-->' ?>
            <div class="products-<?= $block->escapeHtmlAttr($mode) ?> <?= $block->escapeHtmlAttr($mode) ?>">
                <ol class="product-items <?= $block->escapeHtmlAttr($type)?>">
                    <?php foreach ($items as $_item) : ?>
                        <li class="product-item">
                            <div class="product-item-info">
                                <a href="<?= $block->escapeUrl($block->getProductUrl($_item)) ?>" class="product-item-photo">
                                    <?= $block->getImage($_item, $image)->toHtml() ?>
                                </a>
                                <div class="product-item-details">
                                    <strong class="product-item-name">
                                        <a title="<?= $block->escapeHtmlAttr($_item->getName()) ?>"
                                           href="<?= $block->escapeUrl($block->getProductUrl($_item)) ?>" class="product-item-link">
                                            <?= $block->escapeHtml($_item->getName()) ?>
                                        </a>
                                    </strong>
                                    <?= /* @noEscape */ $block->getProductPriceHtml(
                                        $_item,
                                        \Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE,
                                        \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST,
                                        [
                                            'price_id_suffix' => '-' . $type
                                        ]
                                    ) ?>
                                    <?php if ($rating) : ?>
                                        <?= $block->getReviewsSummaryHtml($_item, $rating) ?>
                                    <?php endif; ?>
                                    <?php if ($showWishlist || $showCompare || $showCart) : ?>
                                        <div class="product-item-actions">
                                            <?php if ($showCart) : ?>
                                                <div class="actions-primary">
                                                    <?php if ($_item->isSaleable()) : ?>
                                                        <?php if ($_item->getTypeInstance()->hasRequiredOptions($_item)) : ?>
                                                            <button class="action tocart primary"
                                                                    data-mage-init='{"redirectUrl": {"url": "<?= $block->escapeUrl($block->getAddToCartUrl($_item)) ?>"}}'
                                                                    type="button" title="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>">
                                                                <span><?= $block->escapeHtml(__('Add to Cart')) ?></span>
                                                            </button>
                                                        <?php else : ?>
                                                            <?php
                                                                $postDataHelper = $this->helper(\Magento\Framework\Data\Helper\PostHelper::class);
                                                                $postData = $postDataHelper->getPostData($block->getAddToCartUrl($_item), ['product' => $_item->getEntityId()])
                                                            ?>
                                                            <button class="action tocart primary"
                                                                    data-post='<?= /* @noEscape */ $postData ?>'
                                                                    type="button" title="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>">
                                                                <span><?= $block->escapeHtml(__('Add to Cart')) ?></span>
                                                            </button>
                                                        <?php endif; ?>
                                                    <?php else : ?>
                                                        <?php if ($_item->getIsSalable()) : ?>
                                                            <div class="stock available"><span><?= $block->escapeHtml(__('In stock')) ?></span></div>
                                                        <?php else : ?>
                                                            <div class="stock unavailable"><span><?= $block->escapeHtml(__('Out of stock')) ?></span></div>
                                                        <?php endif; ?>
                                                    <?php endif; ?>
                                                </div>
                                            <?php endif; ?>

                                            <?php if ($showWishlist || $showCompare) : ?>
                                                <div class="actions-secondary" data-role="add-to-links">
                                                    <?php if ($this->helper(\Magento\Wishlist\Helper\Data::class)->isAllow() && $showWishlist) : ?>
                                                        <a href="#"
                                                           data-post='<?= /* @noEscape */ $block->getAddToWishlistParams($_item) ?>'
                                                           data-action="add-to-wishlist"
                                                           class="action towishlist"
                                                           title="<?= $block->escapeHtmlAttr(__('Add to Wish List')) ?>">
                                                            <span><?= $block->escapeHtml(__('Add to Wish List')) ?></span>
                                                        </a>
                                                    <?php endif; ?>
                                                    <?php if ($block->getAddToCompareUrl() && $showCompare) : ?>
                                                        <?php $compareHelper = $this->helper(\Magento\Catalog\Helper\Product\Compare::class); ?>
                                                        <a href="#" class="action tocompare"
                                                           data-post='<?= /* @noEscape */ $compareHelper->getPostDataParams($_item) ?>'
                                                           title="<?= $block->escapeHtmlAttr(__('Add to Compare')) ?>">
                                                            <span><?= $block->escapeHtml(__('Add to Compare')) ?></span>
                                                        </a>
                                                    <?php endif; ?>
                                                </div>
                                            <?php endif; ?>
                                        </div>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </li>
                    <?php endforeach ?>
                </ol>
            </div>
            <?= $block->getPagerHtml() ?>
        </div>
    </div>
<?php endif;?>
