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

// phpcs:disable Magento2.Templates.ThisInTemplate.FoundThis
?>
<?php
/** @var $block \Magento\LayeredNavigation\Block\Navigation\FilterRenderer */
/** @var \Magento\LayeredNavigation\ViewModel\Layer\Filter $viewModel */
$viewModel = $block->getData('product_layer_view_model');
?>

<ol class="items">
    <?php foreach ($filterItems as $filterItem): ?>
		<?php
        $filter = $filterItem->getFilter();
        $inputName = $filter->getRequestVar();
        ?>
        <li class="item">
            <?php if ($filterItem->getCount() > 0): ?>
                <a href="<?= $block->escapeUrl($filterItem->getUrl()) ?>" rel="nofollow">
                    <?= /* @noEscape */ $filterItem->getLabel() ?>
					<?php if ($inputName == 'cat' || $inputName == 'product_brand' || $inputName == 'price'): ?>
						<span class="count"><?= /* @noEscape */ (int)$filterItem->getCount() ?>
							  <span class="filter-count-label">
								<?php if ($filterItem->getCount() == 1):
									?> <?= $block->escapeHtml(__('item')) ?><?php
								else:
									?> <?= $block->escapeHtml(__('item')) ?><?php
								endif;?></span></span>
					<?php else: ?> 
						<?php if ($viewModel->shouldDisplayProductCountOnLayer()): ?>
							<span class="count"><?= /* @noEscape */ (int)$filterItem->getCount() ?>
							  <span class="filter-count-label">
								<?php if ($filterItem->getCount() == 1):
									?> <?= $block->escapeHtml(__('item')) ?><?php
								else:
									?> <?= $block->escapeHtml(__('item')) ?><?php
								endif;?></span></span>
						<?php endif; ?>
					<?php endif;?>
                </a>
            <?php else: ?>
                <?= /* @noEscape */ $filterItem->getLabel() ?>
				<?php if ($inputName == 'cat' || $inputName == 'product_brand' || $inputName == 'price'): ?>
					<span class="count"><?= /* @noEscape */ (int)$filterItem->getCount() ?>
                      <span class="filter-count-label">
                        <?php if ($filterItem->getCount() == 1):
                            ?><?= $block->escapeHtml(__('items')) ?><?php
                        else:
                            ?><?= $block->escapeHtml(__('items')) ?><?php
                        endif;?></span></span>
				<?php else: ?> 
					<?php if ($viewModel->shouldDisplayProductCountOnLayer()): ?>
						<span class="count"><?= /* @noEscape */ (int)$filterItem->getCount() ?>
						  <span class="filter-count-label">
							<?php if ($filterItem->getCount() == 1):
								?><?= $block->escapeHtml(__('items')) ?><?php
							else:
								?><?= $block->escapeHtml(__('items')) ?><?php
							endif;?></span></span>
					<?php endif; ?>
				<?php endif;?>
            <?php endif; ?>
        </li>
    <?php endforeach ?>
</ol>
