<ul class="site-nav list--inline {{ nav_alignment }}" id="SiteNav">
  {% for link in linklists[section.settings.main_linklist].links %}
  {%- assign child_list_handle = link.title | handleize -%}

  {% comment %}
  Check if third-level nav exists on each parent link.
  {% endcomment %}
  {%- assign three_level_nav = false -%}
  {% if link.links != blank %}
  {% if link.levels == 2 %}
  {%- assign three_level_nav = true -%}
  {% endif %}
  {% endif %}

  {% if link.links != blank %}
  <li class="site-nav--has-dropdown {% if three_level_nav %} site-nav--has-centered-dropdown {% else %}count_li {% endif %}{% if link.active %} site-nav--active{% endif %}" aria-haspopup="true" aria-controls="SiteNavLabel-{{ child_list_handle }}">
    <a href="{{ link.url }}" class="site-nav__link site-nav__link--main"{% if link.active %} aria-current="page"{% endif %} aria-expanded="false">
      {{ link.title }}
      {% include 'icon-chevron-down' %}
    </a>

    <div class="site-nav__dropdown{% if three_level_nav %} site-nav__dropdown--centered{% endif %}" id="SiteNavLabel-{{ child_list_handle }}">
      {% if three_level_nav %}
      <div class="site-nav__childlist">
        <ul class="site-nav__childlist-grid">
          {% if link.links != blank %}

          {% for childlink in link.links limit:5%}
          {% assign collection = childlink.object %}
          <li class="site-nav__childlist-item count-column {% if childlink.links != blank %} left {% elsif collection.image %}center {% endif %}">
            {% if childlink.links != blank %}
            <a href="{{ childlink.url }}" class="site-nav__link site-nav__child-link site-nav__child-link--parent"{% if childlink.active %} aria-current="page"{% endif %}>
              {{ childlink.title | escape }}
            </a>
            {% else %}
            <a href="{{ childlink.url }}" class="{% if collection.image %}hide {% endif %}site-nav__link site-nav__child-link site-nav__child-link--parent"{% if childlink.active %} aria-current="page"{% endif %}>
              {{ childlink.title | escape }}
            </a>
            {% endif%}
            {% if childlink.links != blank %}
            <ul>
              {% for grandchildlink in childlink.links %}
              <li>
                <a href="{{ grandchildlink.url }}" class="site-nav__link site-nav__child-link"{% if grandchildlink.active %} aria-current="page"{% endif %}>
                  {{ grandchildlink.title | escape }}
                </a>
              </li>
              {% endfor %}
            </ul>
            {% else %}
            {% assign collection = childlink.object %}
            {% if childlink.type == 'collection_link' %}
            {% if collection.image %}
            <div class="coll_image">
              <a class="collection-link-menu" href="{{ childlink.url }}">
                <div class="collection-grid-item__overlay">
                  <img src="{{ collection | img_url: '500x' }}"  alt="{{ collection.title | escape }}"/>
                </div>
                <div class="collection-grid-item__title-wrapper">
                  <h3 class="collection-grid-item__title">

                    {{ childlink.title }}

                  </h3>
                  {% if settings.show_view_all %}
                  <div class="text-center coll_all">
                    <span class="btn_all btn">{{ settings.btn_text }}</span>
                  </div>
                  {% endif %}

                </div>
              </a>
            </div>
            {% else %}
            test
            {% endif %}
            {% endif %}
            {% endif %}

          </li>
          {% endfor %}

          {% endif %}
        </ul>
      </div>

      {% else %}
      <ul>
        {% for childlink in link.links %}
        <li {% if childlink.active %}class="site-nav--active"{% endif %}>
          <a href="{{ childlink.url }}" class="site-nav__link site-nav__child-link{% if forloop.last %} site-nav__link--last{% endif %}"{% if childlink.active %} aria-current="page"{% endif %}>
            {{ childlink.title | escape }}
          </a>
        </li>
        {% endfor %}
      </ul>
      {% endif %}
    </div>




  </li>
  {% else %}
  <li{% if link.active %} class="site-nav--active"{% endif %}>
    <a href="{{ link.url }}" class="site-nav__link site-nav__link--main"{% if link.active %} aria-current="page"{% endif %}>{{ link.title }}</a>
  </li>
  {% endif %}
  {% endfor %}
  {% comment %}
  {% if shop.customer_accounts_enabled %}
  {% if customer %}
  <li>
    <a href="/account" class="site-nav__link site-nav__link--main">{{ 'layout.customer.account' | t }}</a>
  </li>
  {% else %}
  <li>
    <a href="/account/login" class="site-nav__link site-nav__link--main"></a>
  </li>
  {% endif %}
  {% endif %}
  {% endcomment %}
</ul>
