{#
   RTD-style version switcher for sphinx-polyversion.

   sphinx-polyversion provides these context variables:
   - current: GitRef object for current version (has .name, .url attributes)
   - tags: List of GitRef objects for tags
   - branches: List of GitRef objects for branches
   - revisions: List of all GitRef objects
   - latest: GitRef for the latest version

   Each GitRef has: name, url, date, type attributes
#}

{%- if current is defined and current %}
<div class="rst-versions" data-toggle="rst-versions" role="note" aria-label="versions">
  <span class="rst-current-version" data-toggle="rst-current-version">
    <span class="fa fa-book"></span>
    v: {{ current.name }}
    <span class="fa fa-caret-down"></span>
  </span>
  <div class="rst-other-versions">
    {# Released Versions (tags) #}
    {%- if tags %}
    <dl>
      <dt>Versions</dt>
      {%- for item in tags %}
      <dd><a href="{{ item.url }}">{{ item.name }}</a></dd>
      {%- endfor %}
    </dl>
    {%- endif %}

    {# Development Branches #}
    {%- if branches %}
    <dl>
      <dt>Branches</dt>
      {%- for item in branches %}
      <dd><a href="{{ item.url }}">{{ item.name }}{% if item.name == 'main' %} (latest){% endif %}</a></dd>
      {%- endfor %}
    </dl>
    {%- endif %}

    {# Links #}
    <dl>
      <dt>On GitHub</dt>
      <dd><a href="https://github.com/CybLow/pypaginate">View Source</a></dd>
      <dd><a href="https://github.com/CybLow/pypaginate/issues">Issues</a></dd>
    </dl>
  </div>
</div>
{%- else %}
{# Fallback when sphinx-polyversion is not used (single version build) #}
<div class="rst-versions" data-toggle="rst-versions" role="note" aria-label="versions">
  <span class="rst-current-version" data-toggle="rst-current-version">
    <span class="fa fa-book"></span>
    v: {{ release }}
    <span class="fa fa-caret-down"></span>
  </span>
  <div class="rst-other-versions">
    <dl>
      <dt>On GitHub</dt>
      <dd><a href="https://github.com/CybLow/pypaginate">View Source</a></dd>
      <dd><a href="https://github.com/CybLow/pypaginate/issues">Issues</a></dd>
    </dl>
  </div>
</div>
{%- endif %}
