{% extends 'knp_menu.html.twig' %}

{% block list %}
{% for item in item.children %}
    {{ block('item') }}
{% endfor %}
{% endblock %}

{% block item %}
{# building the class of the item #}
{%- set classes = item.attribute('class') is not empty ? [item.attribute('class')] : [] %}
{%- if matcher.isCurrent(item) %}
    {%- set classes = classes|merge([options.currentClass]) %}
{%- elseif matcher.isAncestor(item, options.matchingDepth) %}
    {%- set classes = classes|merge([options.ancestorClass]) %}
{%- endif %}
{%- if item.actsLikeFirst %}
    {%- set classes = classes|merge([options.firstClass]) %}
{%- endif %}
{%- if item.actsLikeLast %}
    {%- set classes = classes|merge([options.lastClass]) %}
{%- endif %}

{# Mark item as "leaf" (no children) or as "branch" (has children that are displayed) #}
{% if item.hasChildren and options.depth is not same as(0) %}
    {% if options.branch_class is not empty and item.displayChildren %}
        {%- set classes = classes|merge([options.branch_class]) %}
    {% endif %}
{% elseif options.leaf_class is not empty %}
    {%- set classes = classes|merge([options.leaf_class]) %}
{%- endif %}

{%- set attributes = item.attributes %}
{%- if classes is not empty %}
    {%- set attributes = attributes|merge({'class': classes|join(' ')}) %}
{%- endif %}
{% if item.level is same as(1) %}
<div class="item {% if attributes.class is defined %}{{ attributes.class }}{% endif %}">
    <div class="header">{{ item.label|trans }}</div>
    <div class="menu">
        {{ block('list') }}
    </div>
</div>
{% else %}
<a class="item {% if attributes.class is defined %}{{ attributes.class }}{% endif %}" href="{{ item.uri }}">
    {{ block('icon') }}
    {{ item.label|trans }}
</a>
{% endif %}
{% endblock %}

{% block icon %}
{% set icon = item.labelAttribute('icon') %}
{% if icon %}<i class="icon {{ icon }}"></i> {% endif %}
{% endblock %}

