<?php
/**
 * @var $block \Mirasvit\LayeredNavigation\Block\Navigation\State
 */

$filters = $block->getActiveFilters();
?>
<?php if (!empty($filters)): ?>
    <div class="card filter-current py-0 shadow-none px-0 <?= $block->isHorizontalFilter() ? 'w-full' : '' ?>" data-mst-nav-part="state" x-data="initLabelRenderer()">
        <ol class="items <?= $block->isHorizontalFilter() ? 'flex felx-wrap' : '' ?>">
            <?php if ($block->isHorizontalFilter()): ?>
                <li class="item block-actions filter-actions font-semibold " data-element="filter" @click="handleClick">
                    <a href="<?= $block->getClearUrl() ?>" class="action clear filter-clear"><span><?= __('Clear All') ?></span></a>
                </li>
            <?php endif ?>

            <?php foreach ($filters as $filter): ?>
                <?php
                $clearLinkUrl = $filter->getClearLinkUrl();
                $filterName   = __($filter->getName());
                $filterLabel  = __($block->stripTags($filter->getLabel()));
                ?>
                <li class="item mst-nav__state-filter cursor-pointer overflow-hidden text-ellipsis px-4 relative py-2 p-1 my-1 -pl-5 <?= !$block->isHorizontalFilter() ? '-pl-5' : '' ?>" data-element="filter" @click="handleClick" style="box-shadow: 0 0px 4px rgb(0, 0, 0, 0.2);">


                    <?php if ($clearLinkUrl): ?>
                        <a class="action previous" rel="<?= $block->escapeHtmlAttr($block->getRelAttributeValue()) ?>" href="<?= $filter->getRemoveUrl() ?>" title="<?= __('Previous') ?>">
                            <span>&#10005;</span>
                        </a>

                        <a class="action remove" rel="<?= $block->escapeHtmlAttr($block->getRelAttributeValue()) ?>"  title="<?= $block->escapeHtml($filter->getFilter()->getClearLinkText()) ?>" href="<?= $clearLinkUrl ?>">
                            <span>&#10005;</span>
                        </a>
                    <?php else: ?>
                        <a
                            class="action remove absolute px-1 <?= !$block->isHorizontalFilter() ? 'left-0 ' : '' ?>"
                            href="<?= $filter->getRemoveUrl() ?>"
                            title="<?= __('Remove %1', $filterLabel) ?>"
                            rel="<?= $block->escapeHtmlAttr($block->getRelAttributeValue()) ?>"
                        >
                            <span class="text-black">
                                <svg width="18" height="24" viewBox="0 0 24 24" fill="none"
                                     xmlns="http://www.w3.org/2000/svg" stroke="black" stroke-width="2"
                                     stroke-linecap="round" stroke-linejoin="round">
                                  <polyline points="20 6 9 17 4 12" />
                                </svg>

                            </span>
                        </a>
                    <?php endif ?>

                    <span class="hidden filter-label font-semibold ml-2"><?= $filterName ?>: </span>
                    <span class="filter-value ml-2 text-base font-medium"><?= $filterLabel ?></span>
                    <?php if ($clearLinkUrl): ?>
                        <a class="action previous" rel="<?= $block->escapeHtmlAttr($block->getRelAttributeValue()) ?>" href="<?= $filter->getRemoveUrl() ?>" title="<?= __('Previous') ?>">
                            <span>&#10005;</span>
                        </a>

                        <a class="action remove" rel="<?= $block->escapeHtmlAttr($block->getRelAttributeValue()) ?>"  title="<?= $block->escapeHtml($filter->getFilter()->getClearLinkText()) ?>" href="<?= $clearLinkUrl ?>">
                            <span>&#10005;</span>
                        </a>
                    <?php else: ?>
                        <a
                            class="action remove absolute px-1 <?= !$block->isHorizontalFilter() ? 'right-0 ' : '' ?>"
                            href="<?= $filter->getRemoveUrl() ?>"
                            title="<?= __('Remove %1', $filterLabel) ?>"
                            rel="<?= $block->escapeHtmlAttr($block->getRelAttributeValue()) ?>"
                        >
                            <span>&#10005;</span>
                        </a>
                    <?php endif ?>
                </li>
            <?php endforeach ?>

            <?php if (!$block->isHorizontalFilter()): ?>
                <li class="item block-actions filter-actions font-semibold absolute top-6 md:top-0 right-10 md:right-4 lg:right-6 text-sm bg-white md:bg-header-darker px-3 py-1" data-element="filter" @click="handleClick">
                    <a href="<?= $block->getClearUrl() ?>" class="action clear filter-clear"><span><?= __('Reset') ?></span></a>
                </li>
            <?php endif ?>
        </ol>
    </div>
<?php endif ?>
