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

// @codingStandardsIgnoreFile

?>
<?php if (($_products = $block->getProductCollection()) && $_products->getSize()): ?>
    <div class="block widget block-new-products-list">
        <div class="block-title">
            <strong><?php /* @escapeNotVerified */ echo __('New Products') ?></strong>
        </div>
        <div class="block-content">
            <?php $suffix = $block->getNameInLayout(); ?>
            <?php $iterator = 1; ?>
            <ol class="product-items" id="widget-new-products-<?php /* @escapeNotVerified */ echo $suffix; ?>">
                <?php foreach ($_products->getItems() 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, 'side_column_widget_product_thumbnail')->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, '-widget-new-' . $suffix) ?>
                            <div class="product-item-actions">
                                <div class="actions-primary">
                                    <?php if ($_product->isSaleable()): ?>
                                        <?php if ($_product->getTypeInstance()->hasRequiredOptions($_product)): ?>
                                            <button type="button" title="<?php /* @escapeNotVerified */ echo __('Add to Cart') ?>"
                                                    class="action tocart primary"
                                                    data-mage-init='{"redirectUrl":{"url":"<?php /* @escapeNotVerified */ echo $block->getAddToCartUrl($_product) ?>"}}'>
                                                <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" title="<?php /* @escapeNotVerified */ echo __('Add to Cart') ?>"
                                                    class="action tocart primary"
                                                    data-post='<?php /* @escapeNotVerified */ echo $postData; ?>'>
                                                <span><?php /* @escapeNotVerified */ echo __('Add to Cart') ?></span>
                                            </button>
                                        <?php endif; ?>
                                    <?php else: ?>
                                        <?php if ($_product->getIsSalable()): ?>
                                            <div class="stock available" title="<?php /* @escapeNotVerified */ echo __('Availability') ?>">
                                                <span><?php /* @escapeNotVerified */ echo __('In stock') ?></span>
                                            </div>
                                        <?php else: ?>
                                            <div class="stock unavailable" title="<?php /* @escapeNotVerified */ echo __('Availability') ?>">
                                                <span><?php /* @escapeNotVerified */ echo __('Out of stock') ?></span>
                                            </div>
                                        <?php endif; ?>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                    </div>
                    <?php echo($iterator == count($_products->getItems())+1) ? '</li>' : '' ?>
                <?php endforeach; ?>
            </ol>
            <?php echo $block->getPagerHtml() ?>
        </div>
    </div>
<?php endif; ?>
