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

// @codingStandardsIgnoreFile

/* @var $block \Magento\Catalog\Block\Product\Compare\ListCompare */
?>
<?php $total = $block->getItems()->getSize() ?>
<?php if ($total): ?>

    <div class="product-comparison">
        <table class="table-comparison" data-tablesaw-mode="swipe">
            <caption class="table-caption u-sr-only"><?= /* @escapeNotVerified */ __('Compare Products') ?></caption>
            <thead>
                <tr>
                    <th scope="col" data-tablesaw-priority="persist"></th>
                    <?php $index = 0; ?>
                    <?php $helper = $this->helper(\Magento\Catalog\Helper\Output::class); ?>
                    <?php /** @var $item \Magento\Catalog\Model\Product */ ?>
                    <?php foreach ($block->getItems() as $item): ?>
                    <th scope="col"></th>
                    <?php endforeach; ?>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <th data-tablesaw-priority="persist"></th>
                    <?php $index = 0; ?>
                    <?php $helper = $this->helper(\Magento\Catalog\Helper\Output::class); ?>
                    <?php /** @var $item \Magento\Catalog\Model\Product */ ?>
                    <?php foreach ($block->getItems() as $item): ?>
                    <td class="table-comparison__heading-col">
                        <a class="product-item-photo" href="<?= /* @escapeNotVerified */ $block->getProductUrl($item) ?>" title="<?= /* @escapeNotVerified */ $block->stripTags($item->getName(), null, true) ?>">
                            <?= $block->getImage($item, 'product_comparison_list')->toHtml() ?>
                        </a><br/>
                        <strong class="product-item-name">
                            <a href="<?= /* @escapeNotVerified */ $block->getProductUrl($item) ?>" title="<?= /* @escapeNotVerified */ $block->stripTags($item->getName(), null, true) ?>">
                                <?= /* @escapeNotVerified */ $helper->productAttribute($item, $item->getName(), 'name') ?>
                            </a>
                        </strong>
                        <?= $block->getReviewsSummaryHtml($item, 'short') ?>

                        <?php $compareHelper = $this->helper(\Magento\Catalog\Helper\Product\Compare::class);?>
                        <div class="secondary-addto-links actions-secondary" data-role="add-to-links">
                                <a href="#" data-post='<?= /* @escapeNotVerified */ $compareHelper->getPostDataRemove($item) ?>'
                                   class="action delete" title="<?= /* @escapeNotVerified */ __('Remove Product') ?>">
                                    <span><?= /* @escapeNotVerified */ __('Remove Product') ?></span>
                                </a>
                            <?php if ($this->helper(\Magento\Wishlist\Helper\Data::class)->isAllow()) : ?>
                                    <a href="#" data-post='<?= /* @escapeNotVerified */ $block->getAddToWishlistParams($item) ?>' class="action towishlist" data-action="add-to-wishlist">
                                        <span><?= /* @escapeNotVerified */ __('Add to Wish List') ?></span>
                                    </a>
                            <?php endif; ?>
                        </div>

                    </td>
                    <?php endforeach; ?>
                </tr>
                <tr>
                    <th class="table-comparison__line-divider filter-controls" data-tablesaw-priority="persist">
                        <div class="field choice"><input id="hide-similar-properties" class="checkbox" title="<?= /* @escapeNotVerified */ __('Differences only') ?>" name="hide-similar-properties" type="checkbox"> <label class="label" for="hide-similar-properties"><span><?= /* @escapeNotVerified */ __('Differences only') ?></span></label>
                        </div>
                    </th>

                    <?php $helper = $this->helper(\Magento\Catalog\Helper\Output::class); ?>
                    <?php /** @var $item \Magento\Catalog\Model\Product */ ?>
                    <?php foreach ($block->getItems() as $item): ?>
                    <td class="table-comparison__line-divider">
                        <div class="product-item-actions hidden-print">
                            <div class="actions-primary">
                                <?php if ($item->isSaleable()): ?>
                                    <form data-role="tocart-form" action="<?= /* @escapeNotVerified */ $this->helper(\Magento\Catalog\Helper\Product\Compare::class)->getAddToCartUrl($item) ?>" method="post">
                                        <?= $block->getBlockHtml('formkey') ?>
                                        <button type="submit" class="action tocart primary">
                                            <span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
                                        </button>
                                    </form>
                                <?php else: ?>
                                    <?php if ($item->getIsSalable()): ?>
                                        <div class="stock available"><span><?= /* @escapeNotVerified */ __('In stock') ?></span></div>
                                    <?php else: ?>
                                        <div class="stock unavailable"><span><?= /* @escapeNotVerified */ __('Out of stock') ?></span></div>
                                    <?php endif; ?>
                                <?php endif; ?>
                            </div>
                        </div>
                    </td>
                    <?php endforeach; ?>
                </tr>
                <tr class="table-comparison__row-bg">
                    <th class="table-comparison__line-divider" data-tablesaw-priority="persist">
                        <strong><?= $block->escapeHtml(__('Price')) ?></strong>
                    </th>
                    <?php $index = 0; ?>
                    <?php $helper = $this->helper(\Magento\Catalog\Helper\Output::class); ?>
                    <?php /** @var $item \Magento\Catalog\Model\Product */ ?>
                    <?php foreach ($block->getItems() as $item): ?>
                        <td class="table-comparison__line-divider">
                            <?= /* @escapeNotVerified */ $block->getProductPrice($item, '-compare-list-top') ?>
                        </td>
                    <?php endforeach; ?>
                </tr>
                <?php foreach ($block->getAttributes() as $attribute): ?>
                    <?php $index = 0; ?>
                    <?php if ($block->hasAttributeValueForProducts($attribute)): ?>
                        <tr class="table-comparison__row-bg">
                            <?php foreach ($block->getItems() as $item): ?>
                                <?php if ($index++ == 0): ?>
                                    <th scope="row" class="table-comparison__line-divider" data-tablesaw-priority="persist">
                                        <strong class="attribute-label">
                                            <?= $block->escapeHtml($attribute->getStoreLabel() ? $attribute->getStoreLabel() : __($attribute->getFrontendLabel())) ?>
                                        </strong>
                                    </th>
                                <?php endif; ?>
                                <td class="table-comparison__line-divider">
                                    <div class="attribute-value">
                                        <?php switch ($attribute->getAttributeCode()) {
                                            default: ?>
                                                <?= /* @escapeNotVerified */ $helper->productAttribute($item, $block->getProductAttributeValue($item, $attribute), $attribute->getAttributeCode()) ?>
                                                <?php break;
                                        } ?>
                                    </div>
                                </td>
                            <?php endforeach; ?>
                        </tr>
                    <?php endif; ?>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <?php if (!$block->isRedirectToCartEnabled()) : ?>
        <script type="text/x-magento-init">
            {
                "[data-role=tocart-form]": {
                    "catalogAddToCart": {}
                }
            }
            </script>
    <?php endif; ?>

    <script type="text/x-magento-init">
            {
                ".table-comparison": {
                    "comparisonTable": {}
                }
            }
            </script>
<?php else: ?>
    <div class="message info empty"><div><?= /* @escapeNotVerified */ __('You have no items to compare.') ?></div></div>
<?php endif; ?>
