{% macro sub_navigation_item(item) %}
  <li class="usa-sidenav__item" href="{{ url_for(item['link']) }}"
      itemprop="itemListElement"
      itemscope
      itemtype="http://schema.org/ListItem"
  >
    <a class="{% if item['link'] == request.endpoint %} usa-current {% endif %}" href="{{ url_for(item['link']) }}" itemprop="item">
      <span itemprop="name">{{item['name']}}</span>
    </a>
    {% if caller %}
      {{ caller() }}
    {% endif %}
  </li>
{% endmacro %}

{% macro sub_navigation_item_sub_navigation(item) %}
  <ul class="usa-sidenav__sublist" itemscope itemtype="http://schema.org/ItemList">
    {% for sub_item in item.sub_navigation_items %}
      {{ sub_navigation_item(sub_item) }}
    {% endfor %}
  </ul>
{% endmacro %}

{% macro sub_navigation(
  item_set
) %}
  <nav aria-label="Side navigation,">
    <ul class="usa-sidenav" itemtype="http://schema.org/ItemList">
      {% for item in item_set %}
        {% if item.sub_navigation_items %}
          {% call sub_navigation_item(item) %}
            {{ sub_navigation_item_sub_navigation(item) }}
          {% endcall %}
        {% else %}
          {{ sub_navigation_item(item) }}
        {% endif %}
      {% endfor %}
    </ul>
  </nav>
{% endmacro %}
