<?php
/**
 * Copyright © Magefan (support@magefan.com). All rights reserved.
 * See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
 *
 * Glory to Ukraine! Glory to the heroes!
 */
?>
<?php
/**
 * Blog related posts template
 *
 * @var $block \Magefan\Blog\Block\Post\View\RelatedProducts
 */
?>

<?php
if ($exist = $block->getItems()->getSize() && $this->displayProducts()) {
    $type = 'related';
    $class = $type;

    $image = 'related_products_list';
    $title = __('Related Products');
    $items = $block->getItems();
    $limit = 0;
    $shuffle = 0;
    $canItemsAddToCart = true;

    $showWishlist = true;
    $showCompare = true;
    $templateType = null;
}
?>

<?php if ($exist):?>
<div class="block <?php echo $class; ?>">
    <div class="block-title title">
        <strong id="block-<?php echo $class?>-heading" role="heading" aria-level="2"><?php echo $title; ?></strong>
    </div>
    <div class="block-content content" aria-labelledby="block-<?php echo $class?>-heading">

        <div class="products wrapper grid products-grid products-<?php echo $type; ?>">
             <amp-carousel
             width="500"
             height="400"
             layout="responsive"
             type="slides"
             autoplay
             delay="5000"
             >
            <?php /*<ol class="products list items product-items">*/ ?>
                <?php $iterator = 1; ?>
                <?php foreach ($items as $_item): ?>
                <?php $available = ''; ?>
                <?php if (!$_item->isComposite() && $_item->isSaleable() && $type == 'related'): ?>
                    <?php if (!$_item->getRequiredOptions()): ?>
                        <?php $available = 'related-available'; ?>
                    <?php endif; ?>
                <?php endif; ?>
                <?php if ($type == 'related' || $type == 'upsell'): ?>
                    <?php echo($iterator++ == 1) ? '<div class="item product product-item" style="display: none;">' : '</div><div class="item product product-item" style="display: none;">' ?>
                <?php else: ?>
                    <?php echo($iterator++ == 1) ? '<div class="item product product-item">' : '</div><div class="item product product-item">' ?>
                <?php endif; ?>
                <div class="product-item-info <?php echo $available; ?>">
                    <?php echo '<!-- ' . $image . '-->' ?>
                    <a href="<?php echo $block->getProductUrl($_item) ?>" class="product photo product-item-photo">
                        <?php echo $block->getImage($_item, $image)->toHtml(); ?>
                    </a>
                    <div class="product details product-item-details">
                        <strong class="product name product-item-name"><a class="product-item-link" title="<?php echo $block->escapeHtml($_item->getName()) ?>" href="<?php echo $block->getProductUrl($_item) ?>">
                            <?php echo $block->escapeHtml($_item->getName()) ?></a>
                        </strong>

                        <?php echo $block->getProductPrice($_item); ?>
                        </div>
                    </div>
                    <?php echo($iterator == count($items)+1) ? '</div>' : '' ?>
                <?php endforeach ?>
            </amp-carousel>
        </div>
    </div>
</div>
<?php endif;?>