<?php
/**
 * @author Amasty Team
 * @copyright Copyright (c) Amasty (https://www.amasty.com)
 * @package Improved Sorting for Magento 2
 */
/**
 * @var \Amasty\Sorting\Block\Widget\Featured $block
 * @var \Magento\Framework\Escaper $escaper
 */
?>

<?php if ($block->getProductCollection() && $block->getProductCollection()->getSize()): ?>
    <?php
    $type = 'widget-product-grid';

    $mode = 'grid';

    $image = 'featured_products_content';
    $items = $block->getProductCollection()->getItems();

    $showWishlist = true;
    $showCompare = true;
    $showCart = true;
    $templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
    $description = false;
    ?>
    <div class="block widget amsorting block-products-list <?= /* @noEscape */ $mode ?>">
        <?php if ($block->getTitle()): ?>
            <div class="block-title">
                <strong><?= $escaper->escapeHtml(__($block->getTitle())) ?></strong>
            </div>
        <?php endif ?>
        <div class="block-content">
            <div class="products-<?= /* @noEscape */ $mode ?> <?= /* @noEscape */ $mode ?>">
                <ol class="product-items <?= /* @noEscape */ $type ?>">
                    <?php $iterator = 1; ?>
                    <?php foreach ($items as $_item): ?>
                        <?= /* @noEscape */ ($iterator++ == 1)
                            ? '<li class="product-item">'
                            : '</li><li class="product-item">' ?>
                        <div class="product-item-info">
                            <a href="<?= $escaper->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="<?= $escaper->escapeHtml($_item->getName()) ?>"
                                       href="<?= $escaper->escapeUrl($block->getProductUrl($_item)) ?>"
                                       class="product-item-link">
                                        <?= $escaper->escapeHtml($_item->getName()) ?>
                                    </a>
                                </strong>
                                <?php if ($templateType): ?>
                                    <?= $block->getReviewsSummaryHtml($_item, $templateType) ?>
                                <?php endif; ?>
                                <?= $block->getProductPriceHtml($_item, $type) ?>
                                <?php if ($showWishlist || $showCompare || $showCart): ?>
                                    <div class="product-item-actions">
                                        <?php if ($showCart): ?>
                                            <div class="actions-primary">
                                                <?php if ($_item->isSaleable()): ?>
                                                    <button class="action tocart primary"
                                                            data-post='<?= /* @noEscape */ $block->getPostData($_item) ?>'
                                                            type="button"
                                                            title="<?= $escaper->escapeHtml(__('Add to Cart')) ?>">
                                                        <span><?= $escaper->escapeHtml(__('Add to Cart')) ?></span>
                                                    </button>
                                                <?php else: ?>
                                                    <?php if ($_item->getIsSalable()): ?>
                                                        <div class="stock available">
                                                            <span><?= $escaper->escapeHtml(__('In stock')) ?></span>
                                                        </div>
                                                    <?php else: ?>
                                                        <div class="stock unavailable">
                                                            <span><?= $escaper->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 ($block->isWishListAllow() && $showWishlist): ?>
                                                    <?php $params = $block->getAddToWishlistParams($_item) ?>
                                                    <a href="#"
                                                       data-post='<?= /* @noEscape */ $params ?>'
                                                       class="action towishlist"
                                                       data-action="add-to-wishlist"
                                                       title="<?= $escaper->escapeHtml(__('Add to Wish List')) ?>">
                                                        <span><?= $escaper->escapeHtml(__('Add to Wish List')) ?></span>
                                                    </a>
                                                <?php endif; ?>
                                                <?php if ($block->getAddToCompareUrl() && $showCompare): ?>
                                                    <?php $params = $block->getCompareHelper()->getPostDataParams($_item) ?>
                                                    <a href="#"
                                                       class="action tocompare"
                                                       data-post='<?= /* @noEscape */ $params ?>'
                                                       title="<?= $escaper->escapeHtml(__('Add to Compare')) ?>">
                                                        <span><?= $escaper->escapeHtml(__('Add to Compare')) ?></span>
                                                    </a>
                                                <?php endif; ?>
                                            </div>
                                        <?php endif; ?>
                                    </div>
                                <?php endif; ?>
                            </div>
                        </div>
                        <?= ($iterator == count($items)+1) ? '</li>' : '' ?>
                    <?php endforeach ?>
                </ol>
            </div>
            <?= $block->getPagerHtml() ?>
        </div>
    </div>
<?php endif;?>
