<?php
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile
?>
<?php
/**
 * Category layered navigation
 *
 * @var $block \Magento\LayeredNavigation\Block\Navigation
 */
?>

<?php if ($block->canShowBlock()): ?>
    <div class="block filter filter-wrapper" id="layered-filter-block" >
        <?php $filtered = count($block->getLayer()->getState()->getFilters()) ?>
        <div class="block-title filter-title" data-count="<?php /* @escapeNotVerified */ echo $filtered; ?>">
            <strong><?php /* @escapeNotVerified */ echo __('Shop By') ?></strong>
        </div>
        <div class="block-content filter-content">
            <?php if ($block->getLayer()->getState()->getFilters()): ?>
                <div class="filter-current--wrapper">
                    <?php echo $block->getChildHtml('state') ?>

                        <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>
                </div>
            <?php endif; ?>

            <?php $accItems = 0; $openItems = '0'; ?>
            <?php foreach ($block->getFilters() as $filter): ?>
                    <?php $accItems++; ?>
                    <?php $openItems .= ' '. $accItems; ?>
            <?php endforeach; ?>

            <?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"><?php /* @escapeNotVerified */ echo __('Shopping Options') ?></strong>
                        <div class="filter-options " id="narrow-by-list" data-mage-init='{"accordion":{"openedState": "active", "collapsible": true, "animate": 200, "active": "<?php echo $openItems; ?>", "multipleCollapsible": true}}'>
                    <?php  $wrapOptions = true; endif; ?>

                    
                    <div data-role="collapsible" class="filter-options-item">
                        <div data-role="title" class="filter-options-title"><?php /* @escapeNotVerified */ echo __($filter->getName()) ?></div>
                        <div data-role="content" class="filter-options-content"><?php /* @escapeNotVerified */ echo $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>

<script type="text/x-magento-init">
{
    ".filter-content": {
        "Magento_Catalog/js/modalFilter": {}
    }
}
</script>
<?php endif; ?>
