{% extends "furo/sidebar/brand.html" %}

{% block brand_content %}
<div class="sidebar-brand">
  <a class="sidebar-brand-text" href="{{ pathto(master_doc) }}">
    {% if logo_url %}
      <img src="{{ logo_url }}" class="sidebar-logo" alt="Logo">
    {% endif %}
  </a>
  <a href="https://gitcode.com/openeuler/yuanrong-datasystem" target="_blank" class="sidebar-brand-name">openYuanrong datasystem</a>
</div>

<!-- Version Switcher in Sidebar -->
<div class="sidebar-version-switcher">
  <select id="version-selector" onchange="switchVersion(this.value)">
    <option value="https://pages.openeuler.openatom.cn/openyuanrong-datasystem/docs/zh-cn/latest/">Latest</option>
    <option value="https://pages.openeuler.openatom.cn/openyuanrong-datasystem/docs/zh-cn/0.7.0/">0.7.0</option>
    <option value="https://pages.openeuler.openatom.cn/openyuanrong-datasystem/docs/zh-cn/0.6.0/">0.6.0</option>
  </select>
</div>

<script>
function switchVersion(url) {
  if (url && url !== '#') {
    // 获取当前页面路径,替换版本前缀
    var currentPath = window.location.pathname;
    var newUrl = url + currentPath.split('/').slice(5).join('/');
    window.location.href = newUrl;
  }
}

// 设置当前版本的选中状态
document.addEventListener('DOMContentLoaded', function() {
  var selector = document.getElementById('version-selector');
  if (selector) {
    var currentHref = window.location.href;
    var options = selector.options;

    for (var i = 0; i < options.length; i++) {
      if (currentHref.includes(options[i].value)) {
        selector.selectedIndex = i;
        break;
      }
    }
  }
});
</script>
{% endblock %}