{# Displays icon-links as list items. #}
{%- macro icon_link_nav_item(url, icon, name, type, attributes='') -%}
  {%- if url | length > 2 %}
        <li class="nav-item">
          {%- set attributesDefault = { "href": url, "title": name, "class": "nav-link pst-navbar-icon", "rel": "noopener", "target": "_blank", "data-bs-toggle": "tooltip", "data-bs-placement": "bottom"} %}
          {%- if attributes %}{% for key, val in attributes.items() %}
            {% set _ = attributesDefault.update(attributes) %}
          {% endfor %}{% endif -%}
          {% set attributeString = [] %}
          {% for key, val in attributesDefault.items() %}
            {%- set _ = attributeString.append('%s="%s"' % (key, val)) %}
          {% endfor %}
          {% set attributeString = attributeString | join(" ") -%}
          <a {{ attributeString }}>
            {%- if type == "fontawesome" -%}
            {%- set icon_parts = icon.split() -%}
            {%- if icon_parts[0] == "fa-custom" -%}
            {#-
              FA v7 no longer resolves custom icon prefixes from CSS class names alone.
              We can keep the fa-custom class for DOM discovery and add these
              data-prefix/data-icon attributes to ensure the custom icon is rendered, and
              that the prefix is resolved correctly. See the discussion at
              https://github.com/pydata/pydata-sphinx-theme/pull/2370#discussion_r3178092050
            -#}
            <i class="{{ icon_parts[0] }} fa-lg" data-prefix="{{ icon_parts[0] }}" data-icon="{{ icon_parts[1][3:] }}" aria-hidden="true"></i>
            {%- else -%}
            <i class="{{ icon }} fa-lg" aria-hidden="true"></i>
            {%- endif -%}
            <span class="visually-hidden">{{ name }}</span>
            {%- elif type == "local" -%}
            <img src="{{ pathto(icon, 1) }}" class="icon-link-image" alt="{{ name }}"/>
            {%- elif type == "url" -%}
            <img src="{{ icon }}" class="icon-link-image" alt="{{ name }}"/>
            {%- else %}
            <span>Incorrectly configured icon link. Type must be `fontawesome`, `url` or `local`.</span>
            {%- endif -%}
          </a>
        </li>
  {%- endif -%}
{%- endmacro -%}
{%- if theme_icon_links -%}
<ul class="navbar-icon-links"
    aria-label="{{ theme_icon_links_label }}">
  {%- for icon_link in theme_icon_links -%}
    {{ icon_link_nav_item(icon_link["url"], icon_link["icon"], icon_link["name"], icon_link.get("type", "fontawesome"), icon_link.get("attributes", {})) -}}
  {%- endfor %}
</ul>
{%- endif -%}
