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

{% block content %}
    <div class="row">
        <div class="col-12 col-lg-9 no-position-mobile">
            <ul class="menu-lvl2">
                {% for taxon in entry.taxon.children %}
                    {{ _self.levels(entry, taxon, 2) }}
                {% endfor %}
            </ul>

            <a class="menu-link menu-see-all" href="{{ path('sylius_shop_product_index', {'slug': entry.taxon.slug}) }}">
                {{ 'app.ui.menu.see_all'|trans }}
                {% include '@SyliusShop/Icons/arrow.html.twig' %}
            </a>
        </div>

        {% if entry.adImage %}
            <div class="col-lg-3 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_taxon') }}">
                    </a>
                {% else %}
                    <img class="img-fluid" src="{{ entry.adImage|imagine_filter('app_shop_megamenu_taxon') }}">
                {% endif %}

                <a class="menu-link menu-see-all-tablet" href="{{ path('sylius_shop_product_index', {'slug': entry.taxon.slug}) }}">
                    {{ 'app.ui.menu.see_all_section'|trans }}
                    {% include '@SyliusShop/Icons/arrow.html.twig' %}
                </a>
            </div>
        {% endif %}
    </div>
{% endblock %}

{% macro levels(entry, taxon, lvl) %}
    {% 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">
                    <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>
{% endmacro %}
