{# @var navigation \Shopware\Core\Content\Category\Tree\Tree #}
{% set activeId = navigation.active.id ?? context.salesChannel.navigationCategoryId %}
{% set isRoot = activeId == context.salesChannel.navigationCategoryId %}
{% set hasNoChildren = navigation.active.childCount == 0 and navigation.active.level == 2 %}
{# Make sure the navigation does not go deeper than 3 levels, if so, reach back to the parent #}
{% if navigation.active.level == 3 %}
{# Custom work to select the parent of the current child #}
{% set children = navigation.children(navigation.active.parentId) %}
{% set active = navigation.children(navigation.active.parentId).active %}
{% elseif hasNoChildren %}
{# Custom work to check if a second level item has no children (and thus is a page without sub-categories) #}
{% set children = navigation %}
{% set active = navigation.active %}
{% else %}
{# Default shopware settings #}
{% set children = navigation.children(activeId) %}
{% set active = navigation.active %}
{% endif %}
{% set headerNavigation = 'Home' in active.breadcrumb %}
{% if headerNavigation == false %}
{# Check if the navigation is from the Header menu, of else (footer). #}
{# TODO make foolproof. Not fully tested. #}
{% set children = navigation %}
{% set active = false %}
{% endif %}
{% block layout_navigation_offcanvas_navigation_categories %}
<div class="navigation-offcanvas-container js-navigation-offcanvas mb-6">
<div class="navigation-offcanvas-overlay-content js-navigation-offcanvas-overlay-content">
{% if (not isRoot) and (hasNoChildren != true) and (headerNavigation) %}
{% sw_include '@Storefront/storefront/layout/navigation/offcanvas/back-link.html.twig' with { item: active } %}
{% endif %}
<ul class="navigation-offcanvas-list">
{% if (not isRoot) and (page.navigation.active.type != "folder") and (hasNoChildren != true) and (headerNavigation) %}
{% sw_include '@Storefront/storefront/layout/navigation/offcanvas/show-active-link.html.twig' with { item: active } %}
{% endif %}
{% set allowListAddition = ['inspiration', 'department', 'brands'] %}
{% set hasListAddition = false %}
{% for allowAddition in allowListAddition %}
{% set categoryName = active.name ?? active.translated.name %}
{% set additionalMenuId = categoryName|lower %}
{% set additionMenus = page.extensions.additional_menus.get(allowAddition ~ '-' ~ additionalMenuId) %}
{% if additionMenus %}
{% set hasListAddition = true %}
{% break %}
{% endif %}
{% endfor %}
{% if hasListAddition %}
<li class="navigation-offcanvas-list-item">
<div class="navigation-offcanvas-link uppercase nav-item nav-link flex justify-between items-center p-4 pb-1 text-base font-bold transition hover:text-grey-600">
<span itemprop="name">{{ 'themeGlobal.navigationCategories'|trans|sw_sanitize }}</span>
</div>
<ul>
{# @var item \Shopware\Core\Content\Category\Tree\TreeItem #}
{% for item in children.tree %}
{% if not bottomMenu %}
{% set item = item.category %}
{% endif %}
{% sw_include '@Storefront/storefront/layout/navigation/offcanvas/addition-item-link.html.twig' with { item: item, activeId: activeId } %}
{% endfor %}
</ul>
</li>
{% for allowAddition in allowListAddition %}
{% set categoryName = active.name ?? active.translated.name %}
{% set additionalMenuId = categoryName|lower %}
{% set additionMenus = page.extensions.additional_menus.get(allowAddition ~ '-' ~ additionalMenuId) %}
{% if additionMenus %}
<li class="navigation-offcanvas-list-item">
<div class="navigation-offcanvas-link uppercase nav-item nav-link flex justify-between items-center p-4 pb-1 text-base font-bold transition hover:text-grey-600">
{% set additionMenuSnippetKey = 'themeGlobal.navigation' ~ allowAddition|capitalize %}
<span itemprop="name">{{ additionMenuSnippetKey|trans|sw_sanitize }}</span>
</div>
<ul>
{% for additionMenu in additionMenus.elements %}
{% sw_include '@Storefront/storefront/layout/navigation/offcanvas/addition-item-link.html.twig' with { item: additionMenu, activeId: activeId } %}
{% endfor %}
</ul>
</li>
{% endif %}
{% endfor %}
{% else %}
{# @var item \Shopware\Core\Content\Category\Tree\TreeItem #}
{% for item in children.tree %}
{% sw_include '@Storefront/storefront/layout/navigation/offcanvas/item-link.html.twig' with { item: item, activeId: activeId } %}
{% endfor %}
{% endif %}
</ul>
{% set bottomMenu = page.header.extensions.additional_menus.get('bottom-menu') %}
{% if bottomMenu and isRoot %}
<ul class="bottom-menu">
{% for item in bottomMenu %}
{% sw_include '@Storefront/storefront/layout/navigation/offcanvas/item-link.html.twig' with {
bottomMenu: true,
item: item,
activeId: activeId
} %}
{% endfor %}
</ul>
{% endif %}
</div>
</div>
{% endblock %}