<?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) 2017 Mageplaza (http://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 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()): ?>
                <?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; ?>
                <div data-role="ln_collapsible" class="filter-options-item" attribute="<?php echo $filter->getRequestVar() ?>">
                    <div data-role="ln_title" class="filter-options-title"><?php /* @escapeNotVerified */ echo __($filter->getName()) ?></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; ?>
