{#
SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
SPDX-License-Identifier: Apache-2.0
#}
{% macro version_switcher_item(label, meta, status, status_class, url, selected=false) -%}
<li class="docs-version-switcher__option">
  {% if selected %}
    <span class="docs-version-switcher__option-link is-current" aria-current="page">
      <span class="docs-version-switcher__option-copy">
        <span class="docs-version-switcher__option-label">{{ label }}</span>
        {% if meta %}
          <span class="docs-version-switcher__option-meta">{{ meta }}</span>
        {% endif %}
      </span>
      <span class="docs-version-switcher__option-trailing">
        {% if status %}
          <span class="docs-version-switcher__pill {{ status_class }}">{{ status }}</span>
        {% endif %}
        <span class="docs-version-switcher__check" aria-hidden="true">
          <svg viewBox="0 0 16 16" focusable="false">
            <path d="M13.28 4.22a.75.75 0 0 1 0 1.06l-6 6a.75.75 0 0 1-1.06 0l-3-3a.75.75 0 0 1 1.06-1.06l2.47 2.47 5.47-5.47a.75.75 0 0 1 1.06 0Z"></path>
          </svg>
        </span>
      </span>
    </span>
  {% else %}
    <a class="docs-version-switcher__option-link" href="{{ url }}">
      <span class="docs-version-switcher__option-copy">
        <span class="docs-version-switcher__option-label">{{ label }}</span>
        {% if meta %}
          <span class="docs-version-switcher__option-meta">{{ meta }}</span>
        {% endif %}
      </span>
      <span class="docs-version-switcher__option-trailing">
        {% if status %}
          <span class="docs-version-switcher__pill {{ status_class }}">{{ status }}</span>
        {% endif %}
      </span>
    </a>
  {% endif %}
</li>
{%- endmacro %}
{% if versions %}
{% set ordered_releases = versions.releases|stable_release_order %}
{% set latest_stable_release = find_latest_stable_release(ordered_releases) %}
{% set recent_release_versions = ordered_releases[1:5] if latest_stable_release else ordered_releases[:5] %}
{% set main_development_version = find_version_by_name(versions.in_development, "main") %}
{% if latest_stable_release and current_version.name == latest_stable_release.name %}
{% set current_label = display_release_label(latest_stable_release.name) %}
{% set current_meta = "Latest stable" %}
{% set current_status = "Stable" %}
{% set current_status_class = "is-stable" %}
{% elif main_development_version and current_version.name == main_development_version.name %}
{% set current_label = "main" %}
{% set current_meta = "Development" %}
{% set current_status = "Prerelease" %}
{% set current_status_class = "is-beta" %}
{% elif is_prerelease_name(current_version.name) %}
{% set current_label = display_release_label(current_version.name) %}
{% set current_meta = "Prerelease snapshot" %}
{% set current_status = "Prerelease" %}
{% set current_status_class = "is-beta" %}
{% else %}
{% set current_label = display_release_label(current_version.name) %}
{% set current_meta = "Release snapshot" %}
{% set current_status = "Stable" %}
{% set current_status_class = "is-stable" %}
{% endif %}
<details class="docs-version-switcher">
  <summary class="docs-version-switcher__summary">
    <span class="docs-version-switcher__eyebrow">Version</span>
    <span class="docs-version-switcher__trigger">
      <span class="docs-version-switcher__trigger-copy">
        <span class="docs-version-switcher__trigger-label">{{ current_label }}</span>
        <span class="docs-version-switcher__trigger-meta">{{ current_meta }}</span>
      </span>
      <span class="docs-version-switcher__trigger-trailing">
        <span class="docs-version-switcher__pill {{ current_status_class }}">{{ current_status }}</span>
        <span class="docs-version-switcher__chevron" aria-hidden="true">
          <svg viewBox="0 0 16 16" focusable="false">
            <path d="M3.22 5.22a.75.75 0 0 1 1.06 0L8 8.94l3.72-3.72a.75.75 0 1 1 1.06 1.06l-4.25 4.25a.75.75 0 0 1-1.06 0L3.22 6.28a.75.75 0 0 1 0-1.06Z"></path>
          </svg>
        </span>
      </span>
    </span>
  </summary>
  <div class="docs-version-switcher__menu-wrap">
    <ul class="docs-version-switcher__menu" role="list">
      {% if latest_stable_release %}
        {{ version_switcher_item(
          display_release_label(latest_stable_release.name),
          "Latest stable",
          "Stable",
          "is-stable",
          display_release_url(latest_stable_release.url, latest_stable_release.name),
          current_version.name == latest_stable_release.name,
        ) }}
      {% endif %}
      {% if main_development_version %}
        {{ version_switcher_item(
          "main",
          "Development",
          "Prerelease",
          "is-beta",
          main_development_version.url,
          current_version.name == main_development_version.name,
        ) }}
      {% endif %}
      {% for item in recent_release_versions %}
        {% set item_meta = "Prerelease snapshot" if is_prerelease_name(item.name) else "Release snapshot" %}
        {% set item_status = "Prerelease" if is_prerelease_name(item.name) else "Stable" %}
        {% set item_status_class = "is-beta" if is_prerelease_name(item.name) else "is-stable" %}
        {{ version_switcher_item(
          display_release_label(item.name),
          item_meta,
          item_status,
          item_status_class,
          display_release_url(item.url, item.name),
          current_version.name == item.name,
        ) }}
      {% endfor %}
    </ul>
  </div>
</details>
{% endif %}
