<?php

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

// @codingStandardsIgnoreFile
use Magento\Catalog\Block\Product\ReviewRendererInterface;
use Magento\CatalogWidget\Block\Product\ProductsList;
use Magento\Framework\App\Action\Action;

/** @var ProductsList $block */
?>
<?php if ($exist = ($block->getProductCollection() && $block->getProductCollection()->getSize())): ?>
	<?php
	$type = 'widget-product-grid';
	$mode = 'grid';
	$image = 'new_products_content_widget_grid';
	$items = $block->getProductCollection()->getItems();
	$showWishlist = true;
	$showCompare = true;
	$showCart = true;
	$templateType = ReviewRendererInterface::DEFAULT_VIEW;
	$description = false;
	$cartIcon = '<svg xmlns="http://www.w3.org/2000/svg" class="minicart-icon-1" width="14" height="16" viewBox="0 0 14 16">
  <path d="M11,3V0H3V3H0V16H14V3H11ZM5,2H9V3H5V2Zm7,12H2V5H3V7H5V5H9V7h2V5h1v9Z"></path>
</svg>';
	$compareIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="15" height="16" viewBox="0 0 15 16">
  <g>
    <polygon points="2 2 8 2 8 0 0 0 0 12 3 12 3 10 2 10 2 2"></polygon>
    <rect x="8" y="2" width="2" height="1"></rect>
    <polygon points="13 6 13 14 6 14 6 6 13 6 13 4 4 4 4 16 15 16 15 6 13 6"></polygon>
  </g>
</svg>';
	?>
	<div id="ox_<?= $block->getNameInLayout() ?>" class="block widget block-products-list <?= /* @noEscape */
	$mode ?>">
		<?php if ($block->getTitle()): ?>
			<div class="block-title">
				<strong><?= $block->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="<?= $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->escapeHtml($_item->getName()) ?>"
									   href="<?= $block->escapeUrl($block->getProductUrl($_item)) ?>"
									   class="product-item-link">
										<?= $block->escapeHtml($_item->getName()) ?>
									</a>
								</strong>
								<?php
								echo $block->getProductPriceHtml($_item, $type);
								echo $block->getMSRPHtml($_item);
								?>

								<?php if ($templateType): ?>
									<?= $block->getReviewsSummaryHtml($_item,
										$templateType) ?>
								<?php endif; ?>

								<?php if ($showWishlist || $showCompare || $showCart): ?>
									<div class="product-item-actions">
										<?php if ($showCart): ?>
											<div class="actions-primary">
												<?php if ($_item->isSaleable() && $showCart): ?>
													<?php $postParams = $block->getAddToCartPostParams($_item); ?>
													<form data-role="tocart-form"
														  data-product-sku="<?= $block->escapeHtml($_item->getSku()) ?>"
														  action="<?= /* @NoEscape */
														  $postParams['action'] ?>" method="post">
														<input type="hidden" name="product"
															   value="<?= /* @escapeNotVerified */
															   $postParams['data']['product'] ?>">
														<input type="hidden" name="<?= Action::PARAM_NAME_URL_ENCODED ?>"
															   value="<?= /* @escapeNotVerified */
															   $postParams['data'][Action::PARAM_NAME_URL_ENCODED] ?>">
														<?= $block->getBlockHtml('formkey') ?>
														<button type="submit"
																title="<?= $block->escapeHtml(__('Add to Cart')) ?>"
																class="action tocart primary">
															<?= $cartIcon ?><span><?= /* @escapeNotVerified */
																__('Add to Cart') ?></span>
														</button>
													</form>
												<?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')->isAllow() && $showWishlist): ?>
													<a href="#"
													   data-post='<?= /* @noEscape */
													   $block->getAddToWishlistParams($_item) ?>'
													   class="action towishlist" data-action="add-to-wishlist"
													   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'); ?>
													<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>
						<?= ($iterator == count($items) + 1) ? '</li>' : '' ?>
					<?php endforeach ?>
				</ol>
			</div>
			<?= $block->getPagerHtml() ?>
		</div>
		<?php if (isset($_item) && $showCart && !$block->isRedirectToCartEnabled()): ?>
			<script type="text/x-magento-init">
			{
				"[data-role=tocart-form], .form.map.checkout": {
					"catalogAddToCart": {
						"product_sku": "<?= /* @NoEscape */
				$_item->getSku() ?>"
					}
				}
			}

			</script>
		<?php endif; ?>
	</div>
<?php endif; ?>
