<?php
/**
 * Webkul Software.
 *
 * @category  Webkul
 * @package   Webkul_AdvancedLayeredNavigation
 * @author    Webkul
 * @copyright Copyright (c) Webkul Software Private Limited (https://webkul.com)
 * @license   https://store.webkul.com/license.html
 */
?>
<?php if ($block->canShowBlock()) : ?>
    <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="<?= /* @noEscape */   $block->escapeHtml($filtered); ?>">
            <strong data-role="title"><?= /* @noEscape */   $block->escapeHtml(__('Shop By')) ?></strong>
        </div>
        <div class="block-content filter-content">
            <?= /* @noEscape */ $block->getChildHtml('state') ?>
            <?php if ($block->getLayer()->getState()->getFilters()) : ?>
                <div class="block-actions filter-actions">
                    <span data-url="<?= /* @noEscape */   $block->escapeHtml($block->getClearUrl()) ?>"   
                    class="wk-filter-action action clear filter-clear">
                    <a href="#"><?= /* @noEscape */   $block->escapeHtml(__('Clear All')) ?></a></span>
                </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">
                        <?= /* @noEscape */   $block->escapeHtml(__('Shopping Options')) ?></strong>
                        <div class="filter-options" id="narrow-by-list" data-role="content" 
                        data-mage-init='{"accordion":{"openedState": "active", "collapsible": true, "active": false, 
                        "multipleCollapsible": false}}'>
                        <?php  $wrapOptions = true;
                    endif; ?>
                    <div data-role="collapsible" class="filter-options-item">
                        <div data-role="title" class="filter-options-title">
                        <?= /* @noEscape */   $block->escapeHtml(__($filter->getName())) ?></div>
                        <div data-role="content" class="filter-options-content">
                        <?= /* @noEscape */  $block->getChildBlock('renderer')->render($filter); ?></div>
                    </div>
                <?php endif; ?>
            <?php endforeach; ?>
            <?php if ($wrapOptions) : ?>
                </div>
            <?php else : ?>
                <script type="x-magento-init">
                    require([
                        'jquery'
                    ], function ($) {
                        $('#layered-filter-block').addClass('filter-no-options');
                    });
                </script>
            <?php endif; ?>
        </div>
    </div>
<?php endif; ?>
<?php
    $formData = [
        'category_url' => $block->getClearUrl()
    ];
    $serializedFormData = $this->helper('Magento\Framework\Json\Helper\Data')->jsonEncode($formData);
    ?>

<script type="text/x-magento-init">
    {
        "*": {
            "customlayer":  <?= /* @noEscape */  $serializedFormData; ?>
        }
    }
</script>