{block name='snippets-linkgroup-recursive'}
    {et_isShopVersionAtLeast value="5.2.0-beta" assign='shopIsAtLeast52'}
    {if isset($linkgroupIdentifier) && (!isset($i) || isset($limit) && $i < $limit)}
        {strip}
            {if !isset($i)}
                {assign var=i value=0}
            {/if}
            {if !isset($limit)}
                {assign var=limit value=3}
            {/if}
            {if !isset($activeId)}
                {assign var=activeId value=0}
                {if isset($Link) && $Link->getID() > 0}
                    {assign var=activeId value=$Link->getID()}
                {elseif JTL\Shop::$kLink > 0}
                    {assign var=activeId value=JTL\Shop::$kLink}
                    {assign var=Link value=JTL\Shop::Container()->getLinkService()->getLinkByID($activeId)}
                {/if}
            {/if}
            {if !isset($activeParents)}
                {if !empty($activeId)}
                    {assign var=activeParents value=JTL\Shop::Container()->getLinkService()->getParentIDs($activeId)}
                {else}
                    {assign var=activeParents value=[]}
                {/if}
            {/if}
            {if !isset($links)}
                {get_navigation linkgroupIdentifier=$linkgroupIdentifier assign='links'}
            {/if}
            {if !empty($links)}
                {block name='snippets-linkgroup-recursive-list'}
                    {foreach $links as $li}
                        {$activeParent=-1}
                        {$hasItems=$li->getChildLinks()->count() > 0 && (($i+1) < $limit)}
                        {if isset($activeParents) && is_array($activeParents) && isset($activeParents[$i])}
                            {$activeParent=$activeParents[$i]}
                        {/if}
                        {$active=$li->getIsActive() || (isset($activeParent) && $activeParent == $li->getID()) || ($li->getID() == $activeId)}
                        {if $hasItems}
                            <li class="link-group-item nav-item {if $hasItems}dropdown{/if}{if $active} active{/if}">
                                {block name='snippets-linkgroup-recursive-link'}
                                    <a class="nav-link dropdown-toggle et-dropdown-toggle" target="_self" href="{$li->getURL()}" data-toggle="collapse"
                                       data-target="#link_box_{$li->getID()}_{$i}"
                                       aria-expanded="{if $active}true{else}false{/if}"
                                       aria-controls="link_box_{$li->getID()}_{$i}">
                                        {$li->getName()}
                                        <i class='{et_getIcon key="dropdownOpen"} et-dropdown-open'></i><i class='{et_getIcon key="dropdownClosed"} et-dropdown-closed'></i>
                                    </a>
                                {/block}
                                {block name='snippets-linkgroup-recursive-has-items-nav'}
                                    <ul class="nav flex-column collapse {if ($li->getReference() > 0 && $li->getReference() == $activeId)
                                        || ($li->getReference() > 0 && $li->getReference() == $activeParent)
                                        || $active}show{/if}" id="link_box_{$li->getID()}_{$i}"
                                    >
                                    {block name='snippets-linkgroup-recursive-include-linkgroup-recursive'}
                                        {if $li->getChildLinks()->count() > 0}
                                            {include file='snippets/linkgroup_recursive.tpl' i=$i+1 links=$li->getChildLinks() limit=$limit activeId=$activeId activeParents=$activeParents}
                                        {else}
                                            {include file='snippets/linkgroup_recursive.tpl' i=$i+1 links=array($li) limit=$limit activeId=$activeId activeParents=$activeParents}
                                        {/if}
                                    {/block}
                                    </ul>
                                {/block}
                            </li>
                        {else}
                            {block name='snippets-linkgroup-recursive-has-not-items'}
                                <li class="nav-item{if $active} active{/if}">
                                    <a href="{$li->getURL()}" class="nav-link"{if $li->getNoFollow()} rel="nofollow"{/if}{if $shopIsAtLeast52} target="{$li->getTarget()}"{/if}>
                                        {$li->getName()}
                                    </a>
                                </li>
                            {/block}
                        {/if}
                    {/foreach}
                {/block}
            {/if}
        {/strip}
    {/if}
{/block}
