<?php
/**
 * @author Amasty Team
 * @copyright Copyright (c) Amasty (https://www.amasty.com)
 * @package Blog Pro for Magento 2
 */
/** @var \Amasty\Blog\Block\Sidebar\Category\TreeRenderer $block */
/** @var \Magento\Framework\Escaper $escaper */

$collection = $block->getCollection();
?>

<?php if (count($collection)): ?>
    <?php foreach ($collection as $category): ?>
        <?php $activeClass = $category->getIsActive() ? 'active' : ''; ?>
        <li class="amblog-category <?= /* @noEscape */ $activeClass; ?> amblog-category-<?= (int)$category->getId(); ?>">
            <a class="amblog-link"
               title="<?= $escaper->escapeHtmlAttr($category->getName()); ?>"
               href="<?= $escaper->escapeUrl($category->getUrl()); ?>">
                <?= $escaper->escapeHtml($category->getName()); ?>
                <span class="amblog-category-count">(<?= $escaper->escapeHtml($block->getPostsCount($category->getId())); ?>)</span>
            </a>

            <?php if ($category->hasActiveChildren()): ?>
                <ul class="amblog-categories -level<?= $category->getLevel() + 1; ?>">
                    <?= /* @noEscape */ $block->renderChildrenItems((int)$category->getCategoryId()); ?>
                </ul>
            <?php endif; ?>
        </li>
    <?php endforeach; ?>
<?php endif; ?>
