{#
/**
 * @file
 * Custom theme implementation for we-mega-menu list item.
 * Adding custom toggler to link element.
 */
#}

{% if attributes.hasClass('dropdown-menu') %}
  {% set attributes = attributes.removeClass('dropdown-menu').addClass('with-submenu') %}
{% endif %}

{% if attributes.description is empty %}
  {% set attributes = attributes.removeAttribute('description') %}
{% endif %}

{% if attributes.hide-sub-when-collapse is empty %}
  {% set attributes = attributes.removeAttribute('hide-sub-when-collapse') %}
{% endif %}

<li {{ attributes }}>
  {% if href is empty %}
    <span data-drupal-link-system-path="<front>" class="we-megamenu-nolink">
      {{ title }}

      {% if content %}
        <span class="d-submenu-toggler"></span>
      {% endif %}
    </span>
  {% else %}
    <a class="we-mega-menu-li" title="{{ attribute(attributes, 'description') }}" href="{{ href }}" {% if attribute(attributes, 'data-target') is not empty %} target="{{ attribute(attributes, 'data-target') }}" {% endif %}>
      {% if (attribute(attributes, 'data-icon') is defined and attribute(attributes, 'data-icon')|trim) %}
        <i class="{{ attribute(attributes, 'data-icon') }}"></i>
      {% endif %}

      {{ title }}

      {% if (attribute(attributes, 'data-caption') is defined and attribute(attributes, 'data-caption')|trim) %}
        <span class="we-mega-menu-caption">{{ attribute(attributes, 'data-caption') }}</span>
      {% endif %}

      {% if content %}
        <span class="d-submenu-toggler"></span>
      {% endif %}
    </a>
  {% endif %}
  {{ content }}
</li>
