<?php
/**
 * *
 *  * Magepow
 *  * @category    Magepow
 *  * @copyright   Copyright (c) 2014 Magepow (http://www.magepow.com/)
 *  * @license     http://www.magepow.com/license-agreement.html
 *  * @Author: DavidDuong
 *  * @@Create Date: 4/16/19 3:12 PM
 *  * @@Modify Date: 3/13/20 3:12 PM
 *
 *
 */

?>
<?php
/**
 * Category layered navigation state
 *
 * @var $block \Magento\LayeredNavigation\Block\Navigation\State
 */
?>
<?php $_filters = $block->getActiveFilters() ?>
<?php if (empty($_filters)) return; ?>
<div class="filter-current"  data-mage-init='{"collapsible":{"openedState": "active", "collapsible": true, "active": true }}'>
    <strong class="block-subtitle filter-current-subtitle widget-title"
        role="heading"
        aria-level="2"
        data-role="title"
        data-count="<?php echo count($_filters); ?>"><?php /* @escapeNotVerified */ echo __('Now Shopping by') ?></strong>
    <ol class="items">
        <?php foreach ($_filters as $_filter): ?>
            <li class="item">
                <span class="filter-label" attribute-code="<?php echo $_filter->getFilter()->getRequestVar() ?>" ><?php echo $block->escapeHtml(__($_filter->getName())); ?></span>
                <span class="filter-value" option-id='<?php echo is_array($_filter->getValue()) ? json_encode($_filter->getValue()) :$_filter->getValue() ?>'><?php /* @escapeNotVerified */ echo $block->stripTags($_filter->getLabel()) ?></span>
                <?php
                $clearLinkUrl = $_filter->getClearLinkUrl();
                $currentFilterName = $block->escapeHtml(__($_filter->getName())) . " " . $block->stripTags($_filter->getLabel());
                if ($clearLinkUrl):
                    ?>
                    <a class="action previous" href="<?php /* @escapeNotVerified */ echo $_filter->getRemoveUrl() ?>"
                       title="<?php /* @escapeNotVerified */ echo __('Previous') ?>">
                        <span><?php /* @escapeNotVerified */ echo __('Previous') ?></span>
                    </a>
                    <a class="action remove"
                       title="<?php echo $block->escapeHtml($_filter->getFilter()->getClearLinkText()) ?>"
                       href="<?php /* @escapeNotVerified */ echo $clearLinkUrl ?>">
                        <span><?php echo $block->escapeHtml($_filter->getFilter()->getClearLinkText()) ?></span>
                    </a>
                <?php else: ?>
                    <?php
                        $removeUrl = $_filter->getRemoveUrl();
                        if($_filter->getFilter()->getRequestVar() == 'price'){
                            $url = html_entity_decode($removeUrl);
                            $removeParam = strtok($url, '?');
                            $parseUrl = parse_url($url);
                            if(isset($parseUrl['query'])){
                                $query = $parseUrl['query'];
                                parse_str($query, $array);
                                unset($array['price']);
                                $queryNotPrice = http_build_query($array);
                                $removeUrl = $queryNotPrice ? $removeParam . '?' . $queryNotPrice : $removeParam;
                            }
                        }
                    ?>                        
                    <a class="action remove" href="<?php /* @escapeNotVerified */ echo $removeUrl ?>"
                       title="<?php /* @escapeNotVerified */ echo $block->escapeHtml(__('Remove')) . " " . $currentFilterName;?>">
                        <span><i class="fa fa-times" aria-hidden="true"></i></span>
                    </a>
                <?php endif; ?>
            </li>
        <?php endforeach; ?>
    </ol>
</div>