{* ET360 uses this template to render categories - and only categories - in product list filters *}
{block name='snippets-categories-mega'}
    {$autoScrollTarget=$autoScrollTarget|default:''}
    {$activeOnly=$activeOnly|default:false}
    {strip}
        {block name='snippets-categories-mega-assigns'}
            {if !isset($i)}
                {assign var=i value=0}
            {/if}
            {$maxLevel=$maxLevel|default:3}
            {$forceOpen=$forceOpen|default:false}
            {$categoryTreeMoreChildrenLimit=$categoryTreeMoreChildrenLimit|default:[]}
            {if !isset($activeId)}
                {if $NaviFilter->hasCategory()}
                    {$activeId = $NaviFilter->getCategory()->getValue()}
                {elseif $nSeitenTyp === $smarty.const.PAGE_ARTIKEL && isset($Artikel)}
                    {$activeId = $Artikel->gibKategorie()}
                {elseif $nSeitenTyp === $smarty.const.PAGE_ARTIKEL && isset($smarty.session.LetzteKategorie)}
                    {$activeId = $smarty.session.LetzteKategorie}
                {else}
                    {$activeId = 0}
                {/if}
            {/if}
        {/block}
        {block name='snippets-categories-mega-categories'}
            {if $Einstellungen.global.global_sichtbarkeit != 3 || JTL\Session\Frontend::getCustomer()->getID() > 0}
                {get_category_array categoryId=0 assign='categories'}
                {if !empty($categories)}
                    {if !isset($activeParents)
                    && ($nSeitenTyp === $smarty.const.PAGE_ARTIKEL || $nSeitenTyp === $smarty.const.PAGE_ARTIKELLISTE)}
                        {get_category_parents categoryId=$activeId assign='activeParents'}
                    {/if}
                    {block name='snippets-categories-mega-categories-inner'}
                        {foreach $categories as $category}
                            {if isset($activeParents) && is_array($activeParents) && isset($activeParents[$i])}
                                {assign var='activeParent' value=$activeParents[$i]}
                            {/if}
                            {if $category->getID() === $activeId
                            || ((isset($activeParent)
                            && isset($activeParent->getID()))
                            && $activeParent->getID() == $category->getID())}
                                {assign var='isActive' value=true}
                                {else}
                                {assign var='isActive' value=false}
                            {/if}
                            {if $category->getID() === $activeId}
                                {assign var='isCurrent' value=true}
                            {else}
                                {assign var='isCurrent' value=false}
                            {/if}
                            {if !$activeOnly || $isActive}
                                {* $category->isOrphaned does not exist before 5.0.2 *}
                                {et_isShopVersionAtLeast value="5.0.2" assign='shopIsAtLeast502'}
                                {if !$shopIsAtLeast502 || $category->isOrphaned() === false}
                                    {if $category->hasChildren() && $maxLevel > 0}
                                        {block name='snippets-categories-mega-category-child'}
                                            <div class="et-categories-mega-main-category" {if !empty($categoryTreeMoreChildrenLimit)} data-item-limit='{json_encode($categoryTreeMoreChildrenLimit)}' data-item-limit-wrapper=".subcategory-wrapper" data-item-limit-item="> .et-categories-mega-sub-category" data-item-limit-more="> .et-item-limit-more"{/if}>
                                                <a href="{if $forceOpen}{$category->getURL()}{if !empty($autoScrollTarget)}{$autoScrollTarget}{/if}{else}#category-mega-collapse-{$category->getID()}{/if}" title="{$category->getName()|escape:'html'}" class="et-collapse et-categories-mega-collapse et-categories-level-{$i}{if $isActive} active{/if}{if $isCurrent} current{/if}"{if !$forceOpen} data-toggle="collapse" role="button" aria-expanded="{if $isActive}true{else}false{/if}" aria-controls="category-mega-collapse-{$category->getID()}"{/if}>
                                                    <span class="text-truncate">{$category->getShortName()}</span>
                                                    {if !$forceOpen}
                                                        {block name='snippets-categories-mega-category-child-icons'}
                                                            <i class='{et_getIcon key="collapseOpen"} et-collapse-open'></i>
                                                            <i class='{et_getIcon key="collapseClosed"} et-collapse-closed'></i>
                                                        {/block}
                                                    {/if}
                                                </a>
                                                <div class="{if !$forceOpen}collapse{if $isActive} show{/if}{/if}" id="category-mega-collapse-{$category->getID()}">
                                                    <div class="subcategory-wrapper">
                                                        {if !$forceOpen}
                                                            <a href="{$category->getURL()}{if !empty($autoScrollTarget)}{$autoScrollTarget}{/if}" title="{$category->getName()|escape:'html'}" class="et-categories-mega-show-all link-discreet">
                                                                <span class="text-truncate">{lang key='menuShow' printf=$category->getShortName()}</span>
                                                            </a>
                                                        {/if}
                                                        {block name='snippets-categories-mega-sub-categories'}
                                                            {if $category->hasChildren()}
                                                                {if !empty($category->getChildren())}
                                                                    {assign var=sub_categories value=$category->getChildren()}
                                                                {else}
                                                                    {get_category_array categoryId=$category->getID() assign='sub_categories'}
                                                                {/if}
                                                                {foreach $sub_categories as $sub}
                                                                    <div class="et-categories-mega-sub-category">
                                                                        {block name='snippets-categories-mega-category-child-body-include-categories-mega-recursive'}
                                                                            {include file='snippets/categories_mega_recursive.tpl'
                                                                                mainCategory=$sub
                                                                                firstChild=true
                                                                                maxLevel=$maxLevel
                                                                                activeId=$activeId
                                                                                activeParents=$activeParents
                                                                                forceOpen=$forceOpen
                                                                                autoScrollTarget=$autoScrollTarget
                                                                                currentLevel=$i + 1
                                                                                categoryTreeMoreChildrenLimit=$categoryTreeMoreChildrenLimit
                                                                            }
                                                                        {/block}
                                                                    </div>
                                                                {/foreach}
                                                                {block name="et-categories-mega-more"}
                                                                    {if !empty($categoryTreeMoreChildrenLimit)}
                                                                        <div class="et-categories-mega-more et-item-limit-more" style="display: none">
                                                                            <a class="link-discreet" href="javascript:void(0);" title="{lang key='showMore' section='global'}">{lang key='showMore' section='global'}</a>
                                                                        </div>
                                                                    {/if}
                                                                {/block}
                                                            {/if}
                                                        {/block}
                                                    </div>
                                                </div>
                                            </div>
                                        {/block}
                                    {else}
                                        {block name='snippets-categories-mega-category-no-child'}
                                            <div class="et-categories-mega-main-category">
                                                <a href="{$category->getURL()}{if !empty($autoScrollTarget)}{$autoScrollTarget}{/if}" title="{$category->getName()|escape:'html'}" class="link-discreet et-categories-mega-link et-categories-level-{$i}{if $isActive} active{/if}{if $isCurrent} current{/if}">
                                                    <span class="text-truncate">{$category->getShortName()}</span>
                                                </a>
                                            </div>
                                        {/block}
                                    {/if}
                                {/if}
                            {/if}
                        {/foreach}
                    {/block}
                {/if}
            {/if}
        {/block}{* /megamenu-categories*}
    {/strip}
{/block}
