<?php
$themeHelper = $this->helper('Wyomind\ElasticsearchCore\Helper\Theme');
$configHelper = $this->helper('Wyomind\ElasticsearchCore\Helper\Config');
$dataHelper = $this->helper('Wyomind\ElasticsearchCore\Helper\Data');
$storeId = $dataHelper->getCurrentStoreId();
if ($configHelper->canUseLayeredNavigation($storeId)) :
?>

<script>
    require(['jquery'], function ($) {
        $(document).on('click', '.eln-debug h3.title', function () {
            $('.eln-debug').toggleClass('visible');
        })
    });
</script>

<div class="eln-debug <?= stripos($themeHelper->getThemeModel(),'Infortis' ) !== false ? 'ultimo' : '' ?>">
    <h3 class="title">LayeredNavigation</h3>
    <div id="eln-debug">
        <span><span class="eln-debug-label">Infinite Scroll?</span</span><br/>
        <span><span class="eln-debug-label">Cache?</span></span><br/>
        <span><span class="eln-debug-label">Elasticsearch?</span></span><br/>
        <span><span class="eln-debug-label">PHP time:</span><span></span></span><br/>
        <span><span class="eln-debug-label">Request time:</span><span></span></span><br/>
        <span><span class="eln-debug-label">Rendering time:</span><span></span></span><br/>
        <span><span class="eln-debug-label">Total time:</span><span></span></span>
        <span id="eln-debug-enable-template-hints"><a href="#" class="eesa-debug-label">Enable Template Hints</a></span>
        <br/>
        <span id="eln-debug-show-last-request-data"><a href="#" class="eesa-debug-label">Show Last Request Data</a></span>
    </div>
</div>

<div id="eln-debug-show-last-request-data-modal"></div>


<script>
    requireDep = ['jquery', 'jquery-ui-modules/dialog', "elasticsearchcore_jsonview"];
    if (!compareVersions(MAGE_VERSION,"2.3.4")) {
        requireDep = ['jquery', 'jquery/ui', "elasticsearchcore_jsonview"];
    }
    require(requireDep, function ($) { // force load of jsonview and modal for later use
        $(".eln-debug").draggable();
    });
</script>

<script id="eln-debug-template" type="text/x-magento-template">
    <span><span class="eln-debug-label">Infinite Scroll?</span><% if (infiniteScroll) { %><span class="eln-debug-yes">Yes</span><% } else { %><span class="eln-debug-no">No</span><% } %></span><br/>
    <span><span class="eln-debug-label">Cache?</span><% if (fromCache) { %><span class="eln-debug-yes">Yes</span><% } else { %><span class="eln-debug-no">No</span><% } %></span><br/>
    <span><span class="eln-debug-label">Elasticsearch?</span><% if (!fromCache) { %><span class="eln-debug-yes">Yes</span><% } else { %><span class="eln-debug-no">No</span><% } %></span><br/>
    <% if (fromCache) { %>
    <span><span class="eln-debug-label">Cache Id:</span><span><%= cacheHash %></span></span><br/>
    <% } %>
    <span><span class="eln-debug-label">PHP time:</span><span><%= phpTime %> ms</span></span><br/>
    <span><span class="eln-debug-label">Request time:</span><span><%= requestTime %> ms</span></span><br/>
    <span><span class="eln-debug-label">Rendering time:</span><span><%= renderingTime %> ms</span></span><br/>
    <span><span class="eln-debug-label">Total time:</span><span><%= totalTime %> ms</span></span>
    <br/>
    <span id="eln-debug-enable-template-hints" <% if (templateHintsEnabled) { %>style="display:none"<% } %>><a href="#" class="eesln-debug-label">Enable Template Hints</a></span>
    <span id="eln-debug-disable-template-hints" <% if (!templateHintsEnabled) { %>style="display:none"<% } %>><a href="#" class="eln-debug-label">Disable Template Hints</a></span>
    <br/>
    <span id="eln-debug-show-last-request-data"><a href="#" class="eln-debug-label">Show Last Request Data</a></span>
</script>

<?php endif;