<?php $_helper = $this->helper('MGS\Ajaxlayernavigation\Helper\Config');?>
<?php if ($block->canShowBlock()): ?>
    <div class="block filter mgs-filter" id="layered-filter-block">
        <div class="block-title filter-title">
            <strong><?php /* @escapeNotVerified */ echo __('Shop By') ?></strong>
        </div>

        <div class="block-content filter-content">
            <?php echo $block->getChildHtml('state') ?>

            <?php //if ($block->getLayer()->getState()->getFilters()): ?>
            <?php if (false): ?>
                <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 (!$wrapOptions): ?>
                    <strong role="heading" aria-level="2" class="block-subtitle filter-subtitle"><?php /* @escapeNotVerified */ echo __('Shopping Options') ?></strong>
                    <dl class="filter-options" id="narrow-by-list">
                <?php $wrapOptions = true; endif; ?>
                    <?php if ($filter->getItemsCount()): ?>
                        <?php
                            if ($filter->getFilterItemsCount()) {
                                $itemIds = $filter->getFilterItemsCount();
                                $attributteId = $filter->getAttributeModel()->getAttributeId();
                                $itemProductIds[$attributteId] = $itemIds[$attributteId];
                            }
                            $class = 'inactive';
                            if (method_exists($filter, "isActive") && $filter->isActive()) {
                                $class = 'active';
                            }
                        ?>
						<div class="filter-item">
                        <dt role="heading" aria-level="3" class="filter-options-title <?php echo $class ?>"><?php echo $block->escapeHtml(__($filter->getName())) ?></dt>
                        <dd class="filter-options-content <?php echo $class ?>"> 
                            <?php 
                            $isPrice = false;
                            if($_helper->usePriceSlide()){ 
                                $maxPrice = 0;
                                $minPrice = 0;

                                if ($filter->hasAttributeModel()) {
                                    $attributeModel = $filter->getAttributeModel();
                                    if ($attributeModel->getAttributeCode() == 'price') { 
                                        $isPrice = true;
                                        $minPrice = $filter->getMinPrice();
                                        $maxPrice = $filter->getMaxPrice();
                                    }
                                }
                            }
                            
                            
                        ?>
                        <?php if ($isPrice) : ?>
                            <div>
                                <input type="text" id="price-range-slider" data-from="<?php echo $minPrice ?>" data-to="<?php echo $maxPrice ?>" name="price-range-slider" />
                            </div>
                        <?php else : ?>
                            <?php /* @escapeNotVerified */ echo $block->getChildBlock('renderer')->render($filter); ?>
                        <?php endif; ?> 
                        </dd>
						</div>
                    <?php endif; ?>
            <?php endforeach; ?>
            <?php if ($wrapOptions): ?>
                </dl>
            <?php endif; ?>
        </div>
    </div>
	<script>
		require([
			'jquery'
		], function($){
			if($('body').hasClass('page-layout-1column')){
				$("#layered-filter-block").detach().appendTo('.category-product-actions');
			}
		});
	</script>
<?php endif; ?>
