<?php
/**
 * Copyright © 2019 Wyomind. All rights reserved.
 * See LICENSE.txt for license details.
 */

/** @var \Wyomind\ElasticsearchCore\Helper\Cart $cartHelper */
$cartHelper = $this->helper('Wyomind\ElasticsearchCore\Helper\Cart');
/** @var \Wyomind\ElasticsearchCore\Helper\Data $dataHelper */
$dataHelper = $this->helper('Wyomind\ElasticsearchCore\Helper\Data');
/** @var \Wyomind\ElasticsearchLayeredNavigation\Helper\Toolbar $toolbarHelper */
$toolbarHelper = $this->helper('Wyomind\ElasticsearchLayeredNavigation\Helper\Toolbar');
/** @var \Magento\Wishlist\Helper\Data $wishlistHelper */
$wishlistHelper = $this->helper('Magento\Wishlist\Helper\Data');
/** @var \Wyomind\ElasticsearchLayeredNavigation\Helper\Config $configHelper */
$configHelper = $this->helper('Wyomind\ElasticsearchLayeredNavigation\Helper\Config');

$coreConfigHelper = $this->helper('Wyomind\ElasticsearchCore\Helper\Config');
/** @var \Wyomind\ElasticsearchLayeredNavigation\Helper\Frontend $frontendHelper */
$frontendHelper = $this->helper('Wyomind\ElasticsearchLayeredNavigation\Helper\Frontend');
/** @var \Magento\Framework\Pricing\Helper\Data $priceHelper */
$priceHelper = $this->helper('Magento\Framework\Pricing\Helper\Data');
/** @var \Wyomind\Core\Helper\Data $coreHelper */
$coreHelper = $this->helper('Wyomind\Core\Helper\Data');

/** @var int $storeId */
$storeId = $dataHelper->getCurrentStoreId();

/** @var boolean $edd */
$edd = $coreHelper->moduleIsEnabled("Wyomind_EstimatedDeliveryDate") && $coreHelper->getStoreConfig("estimateddeliverydate/common/enabled", $storeId);

/** @var string $uenc */
$uenc = $cartHelper->getUenc();

/** @var string $currentMode */
$currentMode = $toolbarHelper->getCurrentMode();

/** @var boolean $wishlistAllow */
$wishlistAllow = $wishlistHelper->isAllow();

/** @var array $labels */
$labels = $configHelper->getLabels($storeId);

?>
<span id="eln-product-products">
    <?php $count = $block->getData('count'); ?>
    <?php $noMoreProduct = $block->getData('noMoreProduct'); ?>
    <?php $products = $block->getData('products'); ?>
    <?php $customerGroupId = $block->getData('customerGroupId'); ?>
    <?php $ajaxCartEnabled = $block->getData('ajaxCartEnabled'); ?>
    <?php $addToCompareEnabled = $block->getData('addToCompareEnabled'); ?>
    <div class="products wrapper <?php echo $currentMode; ?> products-<?php echo $currentMode; ?>">
        <?php if ($count > 0) : ?>
            <ol class="products list items product-items">
            <?php foreach ($products as $product) : ?>
                <li class="item product product-item">
                    <div class="loader"></div>
                    <div class="ajax-cart-message message"></div>
                <div class="product-item-info" data-container="product-grid">
                    <a href="<?= $product['url'] ?>" class="product photo product-item-photo" tabindex="-1">
                        <span class="product-image-container" style="width:240px;">
                            <span class="product-image-wrapper" style="padding-bottom: 125%;">
                                <img class="product-image-photo" id="product-image-<?= $product['id'] ?>" src="<?= $product['base_image'] ?? $product['image'] ?>"
                                     width="240" height="300">
                            </span>
                        </span>
                        <?php if ($coreHelper->getStoreConfig("quickview/settings/enabled")): ?>
                        <a name='quickview-anchor-<?= $product['id'] ?>' class='quickview' id='quickview-<?= $product['id'] ?>' data-quickview-id='<?= $product['id'] ?>'></a>
                        <?php endif; ?>
                    </a>
                    <div class="product details product-item-details eln-product-item-details">
                        <strong class="product name product-item-name">
                            <a class="product-item-link" href="<?= $product['url'] ?>"><?= $product['name'] ?></a>
                        </strong>
                        <?php if ($product['review_count'] > 0) : ?>
                            <div class="product-reviews-summary short">
                                <div class="rating-summary">
                                    <span class="label"><span><?= __("Rating:") ?></span></span>
                                    <div class="rating-result" title="<?= $product['rating'] ?>%">
                                        <span style="width:<?= $product['rating'] ?>%"><span><?= $product['rating'] ?>
                                                %</span></span>
                                    </div>
                                </div>
                                <div class="reviews-actions">
                                    <a class="action view"
                                       href="<?= $product['url'] ?>#reviews"><?= $product['review_count'] ?>
                                        &nbsp;<span><?= __("Reviews") ?></span></a>
                                </div>
                            </div>
                        <?php endif; ?>
                        <?php if (isset($product['prices_' . $customerGroupId])) : ?>
                            <?php if (!isset($product['tax_class_id'])) : $product['tax_class_id'] = 0; endif; ?>
                            <div class="price-box price-final_price">
                                <?php $product['prices'] = $product['prices_' . $customerGroupId]; ?>
                                <span class="price-container price-final_price tax weee">
                                    <span class="price-wrapper">
                                    <?php if ($product['type_id'] == "configurable") : ?>
                                        <?php if ($product['prices']['min_price'] != $product['prices']['max_price']) : ?>
                                            <span><?php echo __('From: '); ?></span><span
                                                    class="price"><?= $priceHelper->currency($frontendHelper->getPrice($product['prices']['final_price']), true, false) ?></span>
                                        <?php else: ?>
                                            <span class="price"><?= $priceHelper->currency($product['prices']['final_price'], true, false) ?></span>
                                        <?php endif; ?>
                                    <?php else: ?>
                                        <?php if ($product['type_id'] == "grouped") : ?>
                                            <span><?php echo __('From: '); ?></span><span
                                                    class="price"><?= $priceHelper->currency($frontendHelper->getPrice($product['prices']['min_price']), true, false) ?></span>
                                        <?php else: ?>
                                            <?php if ($product['type_id'] == "bundle") : ?>
                                                <span><?php echo __('From: '); ?></span><span
                                                        class="price"><?= $priceHelper->currency($frontendHelper->getPrice($product['prices']['min_price']), true, false) ?></span>
                                                <br/>
                                                <span><?php echo __('To: '); ?></span><span
                                                        class="price"><?= $priceHelper->currency($frontendHelper->getPrice($product['prices']['max_price']), true, false) ?></span>
                                            <?php else: ?>
                                                <?php if ($product['prices']['final_price'] < $product['prices']['price']): ?>
                                                    <?php
                                                    if (isset($product['special_from_date'])) :
                                                        $tmp = strtotime($product['special_from_date']);
                                                        $product['special_from_date'] = $tmp;
                                                    endif;
                                                    if (isset($product['special_to_date'])) :
                                                        $tmp = strtotime($product['special_to_date']);
                                                        $product['special_to_date'] = $tmp;
                                                    endif;
                                                    ?>
                                                    <?php if (((isset($product['special_from_date']) && $product['special_from_date'] <= time()) && (isset($product['special_to_date']) && time() <= $product['special_to_date']))
                                                        || (isset($product['special_from_date']) && !isset($product['special_to_date']) && $product['special_from_date'] <= time())
                                                        || (isset($product['special_to_date']) && !isset($product['special_from_date']) && time() <= $product['special_to_date'])
                                                        || (!isset($product['special_to_date']) && !isset($product['special_from_date']))) : ?>
                                                        <p class="old-price">
                                                            <span class="price"><?= $priceHelper->currency($frontendHelper->getPrice($product['prices']['price'], $product['tax_class_id']), true, false) ?></span>
                                                        </p>
                                                        <p class="special-price">
                                                            <span class="price"><?= $priceHelper->currency($frontendHelper->getPrice($product['prices']['final_price'], $product['tax_class_id']), true, false) ?></span>
                                                        </p>
                                                    <?php else: ?>
                                                        <span class="regular-price">
                                                            <span class="price"><?= $priceHelper->currency($frontendHelper->getPrice($product['prices']['price'], $product['tax_class_id']), true, false) ?></span>
                                                        </span>
                                                    <?php endif; ?>
                                                <?php else: ?>
                                                    <span class="regular-price">
                                                      <span class="price"><?= $priceHelper->currency($frontendHelper->getPrice($product['prices']['price'], $product['tax_class_id']), true, false) ?></span>
                                                    </span>
                                                <?php endif; ?>
                                            <?php endif; ?>
                                        <?php endif; ?>
                                    <?php endif; ?>
                                     </span>
                                </span>
                            </div>
                        <?php endif; ?>

                        <?php if (isset($product['configurable_options'])): ?>
                            <div class="swatch-opt">
                                <div class='eln-message-options-error'><?= __("Please select options before adding the product to the cart.") ?></div>
                                <?php // visual swatch before text swatch ?>
                                <?php foreach ($product['configurable_options'] as $attributeCode => $option): ?>
                                    <?php if ($option['visualSwatch']) : ?>
                                        <div class="swatch-attribute color">
                                        <div class="swatch-attribute-options clearfix">
                                            <?php foreach ($option['values'] as $value): ?>
                                            <?php if (substr($value['swatch'],0,1) == "/") : ?>
                                                <div class="swatch-option color" product-id="<?= $product['id'] ?>"
                                                     attribute-id="<?= $option['id'] ?>" option-id="<?= $value['id'] ?>"
                                                     style="background: url(<?php echo $coreConfigHelper->getEnablePubFolder() ? "pub/" : ""; ?>media/attribute/swatch<?= $value['swatch'] ?>) no-repeat center;
                                                             background-size: 100%;"><?= $value['swatch']??$value['label'] ?>
                                                </div>
                                            <?php else: ?>
                                                <div class="swatch-option color" product-id="<?= $product['id'] ?>"
                                                     attribute-id="<?= $option['id'] ?>" option-id="<?= $value['id'] ?>"
                                                     style="background: <?= $value['swatch'] ?> no-repeat center;
                                                             background-size: initial;"><?= $value['swatch']??$value['label'] ?>
                                                </div>
                                            <?php endif; ?>
                                            <?php endforeach; ?>
                                        </div>
                                    </div>
                                    <?php else: ?>
                                        <div class="swatch-attribute text">
                                            <div class="swatch-attribute-options clearfix">
                                                <?php foreach ($option['values'] as $value): ?>
                                                    <div class="swatch-option text" product-id="<?= $product['id'] ?>"
                                                         attribute-id="<?= $option['id'] ?>"
                                                         option-id="<?= $value['id'] ?>"><?= $value['swatch']??$value['label'] ?>
                                                </div>
                                                <?php endforeach; ?>
                                            </div>
                                        </div>
                                    <?php endif; ?>
                                <?php endforeach; ?>
                            </div>
                        <?php endif; ?>

                        <div class="product description product-item-description">
                            <span class="inner-description"><?= $product['description'] ?? ''; ?></span>
                            <a href="<?= $product['url'] ?>"
                               title="<?php if (isset($product['name_no_highlight'])) : ?><?= $product['name_no_highlight'] ?><?php else: ?><?= $product['name'] ?><?php endif; ?>"
                               class="action more"><?= __('Learn More') ?></a>
                        </div>


                        <div class="product-item-inner">
                            <?php if ($edd): ?>
                                <div class="edd-loading" id='estimated-delivery-date-<?= $product['id'] ?>'></div>
                            <?php endif; ?>
                            <div class="product actions product-item-actions">
                                <div class="actions-primary">
                                    <?php if ($ajaxCartEnabled) : ?>
                                        <div <?php else: ?>
                                    <form <?php endif; ?>data-role="tocart-form"
                                          action="<?= str_replace("productId", $product['id'], $cartHelper->getAddUrlPlaceHolder()); ?>"
                                          method="post">
                                    <input type="hidden" name="product" value="<?= $product['id'] ?>">
                                    <input type="hidden" name="uenc" value="<?php echo $uenc; ?>">
                                    <input type="hidden" name="qty" value="1">
                                        <?php if ($ajaxCartEnabled) : ?><input type="hidden" name="isAjax"
                                                                               value="1"><?php endif; ?>
                                        <?php if (isset($product['configurable_options'])): ?>
                                            <?php foreach ($product['configurable_options'] as $attributeCode => $option): ?>
                                                <input class="swatch-input super-attribute-select"
                                                       id="cart-super-attribute-<?= $product['id'] ?>-<?= $option['id'] ?>"
                                                       name="super_attribute[<?= $option['id'] ?>]" type="text"
                                                       value=""/>
                                            <?php endforeach; ?>
                                        <?php endif; ?>
                                        <?php echo $block->getBlockHtml('formkey') ?>
                                        <button type="submit"
                                                title="<?php if (isset($product['quantity_and_stock_status_ids']) && $product['quantity_and_stock_status_ids'] == 0): ?>><?php echo __("The product is not available"); ?><?php else: ?><?php echo __("Add to Cart"); ?><?php endif; ?>"
                                                class="eln-ajax-add-to-cart action tocart primary <?php if (isset($product['quantity_and_stock_status_ids']) && $product['quantity_and_stock_status_ids'] == 0): ?>disabled<?php endif; ?>">
                                        <span>Add to Cart</span>
                                    </button>
                                        <?php if ($ajaxCartEnabled) : ?>
                                </div>
                                <?php else: ?>
                                    </form>
                                <?php endif; ?>
                            </div>
                            <div data-role="add-to-links" class="actions-secondary">
                                <?php if ($wishlistAllow) : ?>
                                    <form data-role="towishlist-form"
                                      action="<?= $block->getUrl("wishlist/index/add") ?>"
                                      method="post" class="towishlist-form">
                                        <input type="hidden" name="product" value="<?= $product['id'] ?>">
                                        <?php echo $block->getBlockHtml('formkey') ?>
                                        <a type="submit" title="<?php echo __("Add to Wish List"); ?>"
                                            class="eln-ajax-add-to-wishlist action towishlist">
                                        </a>
                                    </form>
                                <?php endif; ?>
                                <?php if ($addToCompareEnabled): ?>
                                    <a title="<?php echo __("Add to Compare"); ?>"
                                       href="<?php echo $block->getUrl("catalog/product_compare/add", ["form_key" => $dataHelper->getFormKey(), "uenc" => $uenc, "product" => $product['id']]); ?>"
                                       class="eln-ajax-add-to-compare action tocompare">
                                <span><?php echo __("Add to Compare"); ?></span>
                                </a>
                                <?php endif; ?>
                            </div>
                        </div>

                    </div>
                </div>
                </li>
            <?php endforeach; ?>
        </ol>
        <?php else : ?>
            <div class="message notice">
            <div><?= __('Your search returned no results.') ?></div>
        </div>
        <?php endif; ?>
    </div>
    <div class="eln-infinite-scroll-loader" id="eln-infinite-scroll-loader"></div>
    <div class="eln-infinite-scroll-end <?= $noMoreProduct ? "active" : "" ?>" id="eln-infinite-scroll-end">
        <div class="message-warning warning message">
            <div>
                <?= $labels['no_more_product'] ?>
            </div>
        </div>
    </div>
</span>


<script id="eln-product-items-template" type="text/x-magento-template">
    <div class="products wrapper <?php echo $currentMode; ?> products-<?php echo $currentMode; ?>">
        <% if (count > 0) { %>
        <ol class="products list items product-items">
        </ol>
        <% } else { %>
        <div class="message notice">
            <div><?= __('Your search returned no results.') ?></div>
        </div>
        <% } %>
    </div>
    <div class="eln-infinite-scroll-loader" id="eln-infinite-scroll-loader"></div>
    <div class="eln-infinite-scroll-end" id="eln-infinite-scroll-end">
        <div class="message-warning warning message">
            <div>
                <?= $labels['no_more_product'] ?>
            </div>
        </div>
    </div>
</script>
<script id="eln-product-item-template" type="text/x-magento-template">
    <li class="item product product-item">
        <div class="loader"></div>
        <div class="ajax-cart-message message"></div>
        <div class="product-item-info" data-container="product-grid">
            <a href="<%= product.url %>" class="product photo product-item-photoproduct-image-photo" tabindex="-1">
                <span class="product-image-container" style="width:240px;">
                    <span class="product-image-wrapper" style="padding-bottom: 125%;">
                        <img class="product-image-photo" id="product-image-<%= product.id %>" src="<% if (typeof product.base_image != "undefined") { %><%= product.base_image %><% } else { %><%= product.image %><% } %>" width="240"
                             height="300">
                    </span>
                </span>
                <?php if ($coreHelper->getStoreConfig("quickview/settings/enabled")): ?>
                <a name='quickview-anchor-<%= product.id %>' data-mage-init='{"Wyomind_QuickView/js/quickview":{"url":"<?=  $block->getUrl("quickview/product/view"); ?>","page":""}}' class='quickview' id='quickview-<%= product.id %>' data-quickview-id='<%= product.id %>'></a>
                <?php endif; ?>
            </a>
            <div class="product details product-item-details eln-product-item-details">
                <strong class="product name product-item-name">
                    <a class="product-item-link" href="<%= product.url %>"><%= product.name%></a>
                </strong>
                <% if (product.review_count > 0) { %>
                <div class="product-reviews-summary short">
                    <div class="rating-summary">
                        <span class="label"><span>Rating:</span></span>
                        <div class="rating-result" title="<%= product.rating %>%">
                            <span style="width:<%= product.rating %>%"><span><%= product.rating %>%</span></span>
                        </div>
                    </div>
                    <div class="reviews-actions">
                        <a class="action view" href="<%= product.url %>#reviews"><%= product.review_count %>&nbsp;<span>Reviews</span></a>
                    </div>
                </div>
                <% } %>
                <% if (typeof product['prices_'+customerGroupId] !== "undefined") { %>
                <div class="price-box price-final_price">
                    <% product.prices = product['prices_'+customerGroupId]; %>
                    <span class="price-container price-final_price tax weee">
                        <span class="price-wrapper">
                            <% if (product.type_id == "configurable") { %>
                                <% if (product.prices.min_price != product.prices.max_price) { %>
                                    <span><?php echo __('From: '); ?></span><span class="price"><%= _.getFormattedPrice(product.prices.final_price) %></span>
                                <% } else { %>
                                    <span class="price"><%= _.getFormattedPrice(product.prices.final_price) %></span>
                                <% } %>
                            <% } else { %>
                                <% if (product.type_id == "grouped") { %>
                                    <span><?php echo __('From: '); ?></span><span class="price"><%= _.getFormattedPrice(product.prices.min_price) %></span>
                                <% } else { %>
                                    <% if (product.type_id == "bundle") { %>
                                        <span><?php echo __('From: '); ?></span><span class="price"><%= _.getFormattedPrice(product.prices.min_price) %></span><br/>
                                        <span><?php echo __('To: '); ?></span><span class="price"><%= _.getFormattedPrice(product.prices.max_price) %></span>
                                    <% } else { %>
                                        <% if (product.prices.final_price < product.prices.price) { %>
                                            <% if (typeof product.special_from_date != "undefined") {
                                                tmp =  product.special_from_date.split(/[- :]/);
                                                product.special_from_date = new Date(tmp[0], tmp[1]-1, tmp[2], tmp[3], tmp[4], tmp[5]).getTime();
                                            } %>
                                            <% if (typeof product.special_to_date != "undefined") {
                                                tmp =  product.special_to_date.split(/[- :]/);
                                                product.special_to_date = new Date(tmp[0], tmp[1]-1, tmp[2], tmp[3], tmp[4], tmp[5]).getTime();
                                            } %>

                                            <% if (((typeof product.special_from_date != "undefined" && product.special_from_date <= Date.now()) && (typeof product.special_to_date != "undefined" && Date.now() <= product.special_to_date))
                                                || (typeof product.special_from_date != "undefined" && typeof product.special_to_date == "undefined" && product.special_from_date <= Date.now())
                                                || (typeof product.special_to_date != "undefined" && typeof product.special_from_date == "undefined" && Date.now() <= product.special_to_date)
                                                || (typeof product.special_to_date == "undefined" && typeof product.special_from_date == "undefined")) { %>
                                                <p class="old-price">
                                                    <span class="price"><%= _.getFormattedPrice(product.prices.price, product.tax_class_id) %></span>
                                                </p>
                                                <p class="special-price">
                                                    <span class="price"><%= _.getFormattedPrice(product.prices.final_price, product.tax_class_id) %></span>
                                                </p>
                                            <% } else { %>
                                                <span class="regular-price">
                                                    <span class="price"><%= _.getFormattedPrice(product.prices.price, product.tax_class_id) %></span>
                                                </span>
                                            <% } %>
                                          <% } else { %>
                                            <span class="regular-price">
                                              <span class="price"><%= _.getFormattedPrice(product.prices.price, product.tax_class_id) %></span>
                                            </span>
                                          <% } %>
                                    <% } %>
                                <% } %>
                            <% } %>
                        </span>
                    </span>
                </div>
                <% } %>
                <% if (product.configurable_options) { %>
                <div class="swatch-opt">
                    <div class='eln-message-options-error'><?= __("Please select options before adding the product to the cart.") ?></div>
                    <?php // visual swatch before text swatch ?>
                    <% _.each(product.configurable_options, function(option, attributeCode) { %>
                    <% if (option.visualSwatch) { %>
                    <div class="swatch-attribute color">
                        <div class="swatch-attribute-options clearfix">
                            <% _.each(option.values, function(value) { %>
                            <div class="swatch-option color" product-id=<%= product.id %> attribute-id="<%= option.id
                                %>" option-id="<%= value.id %>" style="background: <%= value.swatch %> no-repeat center;
                                background-size: initial;"><% if (!value.swatch) { %><%= value.label %><% } %>
                            </div>
                            <% }) %>
                        </div>
                    </div>
                    <% } else { %>
                    <% if (option.textSwatch) { %>
                    <div class="swatch-attribute text">
                        <div class="swatch-attribute-options clearfix">
                            <% _.each(option.values, function(value) { %>
                            <div class="swatch-option text" product-id=<%= product.id %> attribute-id="<%= option.id %>"
                                option-id="<%= value.id %>"><% if (value.swatch) { %><%= value.swatch %><% } else { %><%= value.label %><% } %>
                            </div>
                            <% }) %>
                        </div>
                    </div>
                    <% } %>
                    <% } %>
                    <% }) %>
                </div>
                <% } %>

                <div class="product description product-item-description">
                    <span class="inner-description"><% if (typeof product.description != "undefined") { %><%= jQuery.truncate(product.description,{words:true,length:150}) %><% } %></span>
                    <a href="<%= product.url %>"
                       title="<% if (product.name_no_highlight) { %><%= product.name_no_highlight %><% } else { %><%= product.name %><% } %>"
                       class="action more"><?= __('Learn More') ?></a>
                </div>

                <div class="product-item-inner">
                    <?php if ($edd): ?>
                        <div class='edd-loading' id='estimated-delivery-date-<%= product.id %>'></div>
                    <?php endif; ?>
                    <div class="product actions product-item-actions">
                        <div class="actions-primary">
                            <% if (ajaxCartEnabled) { %>
                            <div
                            <% } else { %>
                            <form
                            <% } %>data-role="tocart-form" action="<%=
                            ("<?php echo $cartHelper->getAddUrlPlaceHolder(); ?>").replace("productId",product.id) %>"
                            method="post">
                            <input type="hidden" name="product" value="<%= product.id %>">
                            <input type="hidden" name="uenc" value="<?php echo $uenc; ?>">
                            <input type="hidden" name="qty" value="1">
                            <% if (ajaxCartEnabled) { %><input type="hidden" name="isAjax" value="1"><% } %>
                            <% _.each(product.configurable_options, function(option, attributeCode) { %>
                            <input class="swatch-input super-attribute-select"
                                   id="cart-super-attribute-<%= product.id %>-<%= option.id %>"
                                   name="super_attribute[<%= option.id %>]" type="text" value=""
                                   style="/*visibility: hidden; position:absolute; left:-1000px*/">
                            <% }) %>
                            <?php echo $block->getBlockHtml('formkey') ?>
                            <button type="submit"
                                    title="<% if (typeof product.quantity_and_stock_status_ids  != "undefined" && product.quantity_and_stock_status_ids == 0) { %><?php echo __("The product is not available"); ?><% } else { %><?php echo __("Add to Cart"); ?><% } %>"
                                    class="eln-ajax-add-to-cart action tocart primary <% if (typeof product.quantity_and_stock_status_ids  != "undefined" && product.quantity_and_stock_status_ids == 0) { %>disabled<% } %>">
                                <span>Add to Cart</span>
                            </button>
                            <% if (ajaxCartEnabled) { %>
                        </div>
                        <% } else { %></form><% } %>
                    </div>
                    <div data-role="add-to-links" class="actions-secondary">
                        <?php if ($wishlistAllow) : ?>
                            <form data-role="towishlist-form"
                                  action="<?= $block->getUrl("wishlist/index/add") ?>"
                                  method="post" class="towishlist-form">
                                <input type="hidden" name="product" value="<%= product.id %>">
                                <?php echo $block->getBlockHtml('formkey') ?>
                                <a type="submit" title="<?php echo __("Add to Wish List"); ?>"
                                   class="eln-ajax-add-to-wishlist action towishlist">
                                </a>
                            </form>
                        <?php endif; ?>
                        <% if (addToCompareEnabled) { %>
                        <a title="<?php echo __("Add to Compare"); ?>"
                           href="<%= ("<?php echo $block->getUrl("catalog/product_compare/add", ["form_key" => $dataHelper->getFormKey(), "uenc" => $uenc, "product" => "productId"]); ?>
                        ").replace("productId",product.id) %>" class="eln-ajax-add-to-compare action tocompare">
                        <span><?php echo __("Add to Compare"); ?></span>
                        </a>
                        <% } %>
                    </div>
                </div>

            </div>

        </div>
        </div>
    </li>
</script>