{**
 * Project-Pro Blog — partial: drzewo kategorii (rekurencyjne)
 *
 * Parametry:
 *   $tree        — wynik BlogCategory::getCategoryTree() z URL-ami
 *   $current_cat — aktualny obiekt BlogCategory lub null
 *}

{if $tree}
<ul class="blog-cat-tree">
    {foreach from=$tree item=node}
        {assign var="cat"       value=$node.category}
        {assign var="children"  value=$node.children}
        {assign var="isActive"  value=($current_cat && $current_cat->id == $cat.id_category)}
        {assign var="hasActive" value=false}

        {* Sprawdź czy aktywna kategoria jest wśród dzieci (do automatycznego rozwinięcia) *}
        {if $current_cat && $children}
            {foreach from=$children item=child}
                {if $child.category.id_category == $current_cat->id}
                    {assign var="hasActive" value=true}
                {/if}
            {/foreach}
        {/if}

        <li class="blog-cat-item{if $isActive} is-active{/if}{if $children} has-children{/if}">

            {if $children}
                <span class="blog-cat-toggle" data-target="#cat-sub-{$cat.id_category}"
                      title="{if $isActive || $hasActive}{l s='Zwiń' mod='projectproblog'}{else}{l s='Rozwiń' mod='projectproblog'}{/if}">
                    {if $isActive || $hasActive}&#9660;{else}&#9658;{/if}
                </span>
            {/if}

            <a href="{$cat.url|escape:'html':'UTF-8'}"
               class="blog-cat-link{if $isActive} active{/if}">
                {$cat.name|escape:'html':'UTF-8'}
            </a>

            {if $children}
                <ul id="cat-sub-{$cat.id_category}"
                    class="{if $isActive || $hasActive}open{/if}">
                    {include
                        file='module:projectproblog/views/templates/front/_category-tree.tpl'
                        tree=$children
                        current_cat=$current_cat}
                </ul>
            {/if}

        </li>
    {/foreach}
</ul>
{/if}
