<?php
/**
 * Mageplaza
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Mageplaza.com license that is
 * available through the world-wide-web at this URL:
 * https://www.mageplaza.com/LICENSE.txt
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade this extension to newer
 * version in the future.
 *
 * @category    Mageplaza
 * @package     Mageplaza_LayeredNavigation
 * @copyright   Copyright (c) Mageplaza (https://www.mageplaza.com/)
 * @license     https://www.mageplaza.com/LICENSE.txt
 */
?>
<?php if ($block->canShowBlock()): ?>
    <?php
    $filters     = $block->getFilters();
    $layerConfig = $this->helper('Mageplaza\LayeredNavigation\Helper\Data')->getLayerConfiguration($filters);
    $filtered    = count($block->getLayer()->getState()->getFilters());
    ?>
    <div class="block filter" id="layered-filter-block"
         data-mage-init='{"collapsible":{"openedState": "active", "collapsible": true, "active": false, "collateral": { "openedState": "filter-active", "element": "body" } }}'>

        <div id="ln_overlay" class="ln_overlay">
            <div class="loader">
                <img src="<?php echo $block->getViewFileUrl('images/loader-1.gif'); ?>" alt="Loading...">
            </div>
        </div>

        <div class="block-title filter-title" data-count="<?php /* @escapeNotVerified */
        echo $filtered; ?>">
            <strong data-role="title"><?php /* @escapeNotVerified */
                echo __('Shop By') ?></strong>
        </div>
        <div class="block-content filter-content" data-mage-init='{"mpLayer": <?php echo $layerConfig ?>}'>
            <?php echo $block->getChildHtml('state') ?>

            <?php if ($block->getLayer()->getState()->getFilters()): ?>
                <div class="block-actions filter-actions">
                    <a href="<?php /* @escapeNotVerified */
                    echo $block->getClearUrl() ?>"
                       class="action clear filter-clear"><span><?php /* @escapeNotVerified */
                            echo __('Clear All') ?></span></a>
                </div>
            <?php endif; ?>

            <?php $wrapOptions = false; ?>
                <?php foreach ($filters as $key => $filter): ?>
            <?php if ($filter->getItemsCount() && $filter->getRequestVar() != 'cat'): ?>
            <?php if (!$wrapOptions): ?>
                <strong role="heading" aria-level="2" class="block-subtitle filter-subtitle"><?php echo __('Shopping Options') ?></strong>
                <div class="filter-options" id="narrow-by-list" data-role="content">
                <?php  $wrapOptions = true; endif; ?>
                <?php $_class = $filter->getRequestVar() == 'cat' || $filter->getRequestVar() == 'size' || $filter->getRequestVar() == 'color' || $filter->getRequestVar() == 'price' ? 'active':'';?>
                <div data-role="ln_collapsible" class="filter-options-item <?php echo $_class;?>" attribute="<?php echo $filter->getRequestVar() ?>">
                    <div data-role="ln_title" class="filter-options-title "><?php /* @escapeNotVerified */ echo __($filter->getName()) ?><span class="toggle"></span></div>
                    <div data-role="ln_content" class="filter-options-content"><?php /* @escapeNotVerified */ echo $block->getChildBlock('renderer')->setFilter($filter)->render($filter); ?></div>
                </div>
                <?php endif; ?>
                <?php endforeach; ?>
                <?php if ($wrapOptions): ?>
            </div>
        <?php else: ?>
            <script>
                require([
                    'jquery'
                ], function ($) {
                    $('#layered-filter-block').addClass('filter-no-options');
                });
            </script>
            <?php endif; ?>

            <?php echo $block->getChildHtml('layer_additional_info') ?>
        </div>
    </div>
<?php endif; ?>
