<?php
/**
 * Copyright © 2019 Wyomind. All rights reserved.
 * See LICENSE.txt for license details.
 */
$configHelper = $this->helper('Wyomind\ElasticsearchLayeredNavigation\Helper\Config');
?>

<?php if ($configHelper->isBreadcrumbEnabled($block->getType())) : ?>

    <?php
    // CUSTOM THEME
    $themeHelper = $this->helper('Wyomind\ElasticsearchCore\Helper\Theme');
    $themeClass = "";
    $theme = ['model' => $themeHelper->getThemeModel()];
    if ($theme['model'] == "Infortis/ultimo") :
        $themeClass = "ultimo";
    endif;

    ?>
    <script id="eln-product-breadcrumb-filter-template" type="text/x-magento-template">
        <% if (!_.isEmpty(filters)) { %>
        <ol class="items">
            <% _.each(filters, function(filter, key) { %>
            <% if (key == "final_price") { %>
            <li class="item wyomind-primary-bgcolor">
                        <span class="filter-label">
                            <a href="#" attribute-code="<%= key %>" class="remove-after">
                                <?php echo __("Price"); ?>
                            </a>
                        </span>
                <span class="filters">
                            <span class="filter-value">
                                <a href="#" attribute-code="<%= key %>" class="remove-after">
                                    <%= _.getFormattedPrice(filter.values.min) %>-<%= _.getFormattedPrice(filter.values.max) %>
                                </a>
                            </span>
                        </span>
                <a class="action remove" href="#" attribute-code="<%= key %>"
                   title="<?= __("Remove Price") ?> <%= filter.values.min %>-<%= filter.values.max %>">
                    <span>Remove Price</span>
                </a>
            </li>
            <% } else { %>
            <% if (key == "rating") { %>
            <li class="item wyomind-primary-bgcolor">
                            <span class="filter-label">
                                <a href="#" attribute-code="<%= key %>" class="remove-after">
                                <?php echo __("Rating"); ?>
                                </a>
                            </span>
                <span class="filters">
                                <% _.each(filter.values, function(label, id) { %>
                                    <% id = id.replace('_','-'); %>
                                    <% if (id != -1) { %>
                                        <span class="filter-value">
                                            <a href="#" attribute-code="<%= key %>" option-id="<%= id %>" option-label="<%= id %>"
                                               class="remove-after-and-others">
                                                <div title="<%= id %> & up"
                                                     style="float: none;max-width: 100%;width: 100%; display:inline">
                                                    <div class="product-reviews-summary short"
                                                         style="display:inline-block">
                                                        <div class="rating-summary">
                                                            <span class="label"><span>Rating:</span></span>
                                                            <div class="rating-result" title="<%= id %>%">
                                                                <span style="width:<%= id %>%"><span><%= id %>%</span></span>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </a>
                                        </span>
                                    <% } else { %>
                                        <span class="filter-value">
                                            <a href="#" attribute-code="<%= key %>" option-id="<%= id %>"  option-label="<%= id %>"
                                               class="remove-after-and-others">
                                            <?php echo __("No rating"); ?>
                                            </a>
                                        </span>
                                    <% } %>
                                <% }) %>
                            </span>
                <a class="action remove" href="#" attribute-code="<%= key %>"
                   title="Remove <?php echo __("Rating"); ?>">
                    <span>Remove <?php echo __("Rating"); ?></span>
                </a>
            </li>
            <% } else { %>
            <% if (typeof filter.label != "undefined") { %>
            <li class="item wyomind-primary-bgcolor">
                                <span class="filter-label">
                                    <a href="#" attribute-code="<%= key %>" class="remove-after">
                                        <%= filter.label %>
                                    </a>
                                </span>
                <span class="filters">
                                    <% _.each(filter.values, function(label, id) { %>
                                        <span class="filter-value">
                                            <a href="#" attribute-code="<%= key %>" option-id="<%= id %>" option-label="<%= label %>"
                                               class="remove-after-and-others">
                                                <%= label %>
                                            </a>
                                        </span>
                                    <% }) %>
                                </span>
                <a class="action remove" href="#" attribute-code="<%= key %>"
                   title="Remove <%= filter.label %>">
                    <span>Remove <%= filter.label %></span>
                </a>
            </li>
            <% } %>
            <% } %>
            <% } %>
            <% }) %>
        </ol>
        <% } %>
    </script>

<?php endif; ?>
