<?php
/* @var \Tangibledesign\MyHome\Widgets\BlogArchive\BlogCategoriesArchiveWidget $mhCurrentWidget */
global $mhCurrentWidget;

$mhCategories = $mhCurrentWidget->getCategories();
$mhActiveCategory = $mhCurrentWidget->getActiveCategory();
$mhIsAllPostsActive = $mhCurrentWidget->isAllPostsActive();
$allPostsClass = 'myhome-blog-categories-archive__category';

if ($mhIsAllPostsActive) {
    $allPostsClass .= ' myhome-blog-categories-archive__category--active';
}
?>
<div class="myhome-blog-categories-archive">
    <a 
        href="<?php echo esc_url(get_post_type_archive_link('post')); ?>"
        class="<?php echo esc_attr($allPostsClass); ?>"
    >
        <?php echo esc_html($mhCurrentWidget->getAllPostsLabel()); ?>
    </a>
    
    <?php foreach ($mhCategories as $mhCategory) : ?>
        <?php
        $categoryClass = 'myhome-blog-categories-archive__category';
        if ($mhActiveCategory === $mhCategory->getId()) {
            $categoryClass .= ' myhome-blog-categories-archive__category--active';
        }
        ?>
        <a 
            href="<?php echo esc_url($mhCategory->getUrl()); ?>"
            class="<?php echo esc_attr($categoryClass); ?>"
        >
            <?php echo esc_html($mhCategory->getName()); ?>
        </a>
    <?php endforeach; ?>
</div>
