<?php
/**
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Smile ElasticSuite to newer
 * versions in the future.
 *
 * @category  Smile
 * @package   Smile\ElasticsuiteCatalog
 * @author    Aurelien FOUCRET <aurelien.foucret@smile.fr>
 * @copyright 2020 Smile
 * @license   Open Software License ("OSL") v. 3.0
 */

/**
 * Template for layer navigation view
 *
 * @var $block \Smile\ElasticsuiteCatalog\Block\Navigation
 */
?>

<?php if ($block->canShowBlock()) : ?>
    <?php $activeFilters = $block->getActiveFilters(); ?>
    <div class="block filter" id="layered-filter-block" data-mage-init='{"collapsible":{"openedState": "active", "collapsible": true, "active": false, "collateral": { "openedState": "filter-active", "element": "body" } }}'>
        <?php $filtered = count($block->getLayer()->getState()->getFilters()) ?>
        <div class="block-title filter-title" data-count="<?= /* @escapeNotVerified */ $filtered ?>">
            <strong data-role="title"><?php /* @escapeNotVerified */ echo __('Shop By') ?></strong>
        </div>

        <div class="block-content filter-content">
            <?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 ($block->getFilters() as $filter) : ?>
                <?php if ($filter->getItemsCount()) : ?>
                    <?php if (!$wrapOptions) : ?>
                        <strong role="heading" aria-level="2" class="block-subtitle filter-subtitle"><?= /* @escapeNotVerified */ __('Shopping Options') ?></strong>
                        <div class="filter-options" id="narrow-by-list" data-role="content" data-mage-init='{"accordion":{"openedState": "active", "collapsible": true, "active": <?php  /* @noEscape */ echo $activeFilters; ?>, "multipleCollapsible": <?= /* @noEscape */ $block->isInline() ? "false" : "true"; ?>}}'>
                            <?php $wrapOptions = true;?>
                    <?php endif; ?>
                    <div data-role="collapsible" class="filter-options-item">
                        <div data-role="title" class="filter-options-title"><?= /* @escapeNotVerified */ __($filter->getName()) ?></div>
                        <div data-role="content" class="filter-options-content"><?= /* @escapeNotVerified */ $block->getChildBlock('renderer')->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; ?>
        </div>
    </div>
<?php endif; ?>
