{% extends "@DediSyliusMegamenuPlugin/Shop/Menu/Tab/_base.html.twig" %}

{% block content %}
    <div class="menu-group-wrapper">
        {% if entry.adImage %}
            <div class="d-none d-lg-block menu-image">
                {% if entry.adUrl %}
                    <a href="{{ entry.adUrl }}">
                        <img class="img-fluid" src="{{ entry.adImage|imagine_filter('app_shop_megamenu_catalog') }}">
                    </a>
                {% else %}
                    <img class="img-fluid" src="{{ entry.adImage|imagine_filter('app_shop_megamenu_catalog') }}">
                {% endif %}
            </div>
        {% endif %}

        <ul class="menu-group">
            {% for rootTaxon in entry.rootTaxons %}
                {{ _self.levels(entry, rootTaxon, 1) }}
            {% endfor %}
        </ul>
    </div>
{% endblock %}

{% macro levels(entry, taxon, lvl) %}
    {% if entry.hasTaxon(taxon) %}
        {% set hasSubmenu = lvl < 3 and taxon.children|length > 0 %}

        <li {% if hasSubmenu %}class="has-submenu"{% endif %}>

            <div class="menu-title title-menu-lvl{{ lvl }}">
                <a class="menu-link" href="{{ path('sylius_shop_product_index', {'slug': taxon.slug,}) }}">
                    {{ taxon.name }}
                </a>
                {% if hasSubmenu %}
                    <span class="menu-link-icon"></span>
                {% endif %}
            </div>

            {% if hasSubmenu %}
                <div class="menu-block">
                    <div class="container {% if lvl==1 %}menu-block-wrapper{% endif %}">
                        <div class="menu-back">
                            <span class="menu-back-icon"></span>
                            <span class="menu-back-link">
                                {{ taxon.name }}
                            </span>
                        </div>

                        <ul class="menu-lvl{{ lvl+1 }}">
                            {% for childTaxon in taxon.children %}
                                {{ _self.levels(entry, childTaxon, lvl+1) }}
                            {% endfor %}
                        </ul>
                        <a class="menu-link menu-see-all" href="{{ path('sylius_shop_product_index', {'slug': taxon.slug}) }}">
                            {{ 'app.ui.menu.see_all'|trans }}
                            {% include '@SyliusShop/Icons/arrow.html.twig' %}
                        </a>
                    </div>
                </div>
            {% endif %}
        </li>
    {% endif %}
{% endmacro %}
