<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
use Magento\Framework\App\Action\Action;

// @codingStandardsIgnoreFile

?>
<?php
/**
 * Product list template
 *
 * @var $block \Magento\Catalog\Block\Product\ListProduct
 */
?>
<?php
$_productCollection = $block->getLoadedProductCollection();
?>

<?php if (!$_productCollection->count()): ?>
    <div class="message info empty"><div><?= __('We can\'t find products matching the selection.') ?></div></div>
<?php else: ?>
<?php
/* helper */
$_helper = $this->helper('Magento\Catalog\Helper\Output');
$imageHelper = $this->helper('Magento\Catalog\Helper\Image');
$themeHelper = $this->helper('Codazon\ThemeLayoutPro\Helper\Data');
$quickShopHelper = $this->helper('Codazon\QuickShop\Helper\Data');
$compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');
$wishlistHelper = $this->helper('Magento\Wishlist\Helper\Data');
$labelHelper = $this->helper('Codazon\ProductLabel\Helper\Data');

/* layout */
$layout = $themeHelper->getBlockPageLayout($block);

/* show on list */
$showDescription = true;
$showSku = $themeHelper->isDisplayOnList('sku');
$showWishlist = $wishlistHelper->isAllow() && $themeHelper->isDisplayOnList('wishlist');
$showCompare = $block->getAddToCompareUrl() && $themeHelper->isDisplayOnList('compare');
$showCart = $themeHelper->isDisplayOnList('addtocart');
$showQuickShop = $themeHelper->isDisplayOnList('quickshop');
$showLabel = $themeHelper->isDisplayOnList('label');
$showThumb = $themeHelper->isDisplayOnList('thumb');
$showName = $themeHelper->isDisplayOnList('name');
$showReview = $themeHelper->isDisplayOnList('review');
$showPrice = $themeHelper->isDisplayOnList('price');

$width = $themeHelper->getProductImageSize('width');
$height = $themeHelper->getProductImageSize('height');
$paddingBottom = $height*100/$width;
$cartWidget = $block->isRedirectToCartEnabled()?'':'data-mage-init=\'{"catalogAddToCart":{}}\'';
$wlLabel = $block->escapeHtml(__('Add to Wish List'));
$cpLabel = $block->escapeHtml(__('Add to Compare'));
$cartLabel = $block->escapeHtml(__('Add to Cart'));
$formKey = $block->getBlockHtml('formkey');
?>
<?= $block->getToolbarHtml() ?>
<?= $block->getAdditionalHtml() ?>
<?php
$viewMode = 'list';
$image = 'category_page_list';
$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::FULL_VIEW;
$pos = $block->getPositioned();
$qtyValidator = $block->escapeHtml(json_encode($themeHelper->getQuantityValidators()));
?>
<div class="products wrapper ctst <?= $viewMode ?> products-<?= $viewMode ?>">
    <?php $iterator = 1; ?>
    <ol class="products list items product-items">
        <?php foreach ($_productCollection as $_product): ?>
        <li class="item product product-item">
            <div class="product-item-info" data-container="product-grid">
                <?php if ($showThumb) : ?>
                <div class="product-item-top">
                    <a href="<?= $_product->getProductUrl() ?>" class="product photo product-item-photo">
                        <span class="product-image-container">
                            <span class="product-image-wrapper" style="padding-bottom: <?= $paddingBottom ?>%;"><?= $themeHelper->getProductImageHtml($_product, $width, $height, $imageHelper, $block) ?></span>
                        </span>
                    </a>
                    <?= $showQuickShop?$quickShopHelper->getQuickShopButton($_product):''; ?>
                    <?= $showLabel?$labelHelper->showLabel($_product):''; ?>
                </div>
                <?php endif ?>
                <div class="product details product-item-details">
                    <?php if ($showName): ?>
                    <strong class="product name product-item-name"><a class="product-item-link" href="<?= $_product->getProductUrl() ?>"><?= $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></strong>
                    <?php if ($showSku) : ?>
                    <div class="product-item-sku"><span class="label"><?= __('SKU: ') ?></span><span class="value"><?= $_product->getData('sku') ?></span></div>
                    <?php endif ?>
                    <?php endif ?>
                    <?= $showReview?$block->getReviewsSummaryHtml($_product, $templateType):'' ?>
                    <?= $showPrice?$block->getProductPrice($_product):'' ?>
                    <?= $block->getProductDetailsHtml($_product) ?>
                    <div class="product-item-inner product-list-style-18">
                        <div class="product actions product-item-actions">
                            <?php if ($showCart) : ?>
                            <div class="actions-primary">
                                <div class="button-wrap">
                                    <div class="cart-qty">
                                    <?php if ($_product->isSaleable()): ?>
                                        <?php $postParams = $block->getAddToCartPostParams($_product); ?>
                                        <form <?= $cartWidget ?> data-product-sku="<?= $block->escapeHtml($_product->getSku()) ?>" data-role="tocart-form" action="<?= $postParams['action']; ?>" method="post">
                                            <input type="hidden" name="product" value="<?= $postParams['data']['product']; ?>">
                                            <input type="hidden" name="<?= Action::PARAM_NAME_URL_ENCODED; ?>" value="<?= $postParams['data'][Action::PARAM_NAME_URL_ENCODED]; ?>">
                                            <?= $formKey ?>
                                            <div class="field qty">
                                                <label class="label" for="qty"><span><?php /* @escapeNotVerified */ echo __('Qty') ?></span></label>
                                                <div class="control">
                                                    <div class="qty-ctl">
                                                        <button title="<?= __('Decrease') ?>" type="button" data-role="change_cart_qty" class="decrease" data-qty="-1" class="decrease"></button>
                                                    </div>
                                                    <input type="number" class="qty" name="qty" maxlength="12" value="<?= $themeHelper->getProductDefaultQty($_product, $block) * 1 ?>" title="<?php echo __('Qty') ?>" class="input-text qty" data-validate="<?= $qtyValidator ?>" />
                                                    <div class="qty-ctl">
                                                        <button aria-label="<?= __('Increase') ?>" type="button" data-role="change_cart_qty" data-qty="1" class="increase"></button>
                                                    </div>
                                                </div>
                                            </div>
                                            <button type="submit" title="<?= $cartLabel ?>" class="action tocart primary"><span><?= $cartLabel ?></span></button>
                                        </form>
                                    <?php else: ?>
                                        <?php if ($_product->getIsSalable()): ?>
                                            <button onclick="document.location.href = '<?= $_product->getProductUrl(); ?>'" class="action tocart primary stock available"><span><?= __('In stock') ?></span></button>
                                        <?php else: ?>
                                            <button class="action tocart primary disabled stock unavailable" disabled><span><?= __('Out of stock') ?></span></button>
                                        <?php endif; ?>
                                    <?php endif; ?>
                                    </div>
                                </div>
                            </div>
                            <?php endif ?>
                            <?php if ($showWishlist || $showCompare): ?>
                            <div data-role="add-to-links" class="actions-secondary">
                                <?php if ($showWishlist): ?>
                                    <a href="#" data-post='<?= $block->getAddToWishlistParams($_product); ?>' class="action towishlist" data-action="add-to-wishlist" title="<?= $wlLabel ?>"><span><?= $wlLabel ?></span></a>
                                <?php endif; ?>
                                <?php if ($showCompare): ?>
                                    <a href="#" class="action tocompare" data-post='<?= $compareHelper->getPostDataParams($_product);?>' title="<?= $cpLabel ?>"><span><?= $cpLabel ?></span></a>
                                <?php endif; ?>
                            </div>
                            <?php endif ?>
                            <?php if ($showDescription):?>
                            <div class="product description product-item-description"><?= $themeHelper->subString($_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description'), 500) ?></div>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
            </div>
        </li>
        <?php endforeach; ?>
    </ol>
</div>
<?= $block->getToolbarHtml() ?>
<?php endif; ?>