(function () {
  function mark() {
    var p = (location.pathname || "/").replace(/\/+$/, "") || "/";
    var links = document.querySelectorAll(".oasis-bottombar a.bb-item");
    var best = null, bestLen = -1;
    links.forEach(function (a) {
      var h = (a.getAttribute("href") || "").replace(/\/+$/, "") || "/";
      if (h === "/") return;
      if (p === h || p.indexOf(h + "/") === 0) {
        if (h.length > bestLen) { best = a; bestLen = h.length; }
      }
    });
    if (best) best.classList.add("current");
  }

  function onToggle(e) {
    var t = e.target;
    if (!t || !t.classList || !t.classList.contains("oasis-nav-toggle")) return;
    if (!t.checked) return;
    var group = t.closest(".oasis-nav-group");
    var scope = group && group.parentElement;
    if (!scope) return;
    var others = scope.querySelectorAll(
      ":scope > .oasis-nav-group > .oasis-nav-toggle"
    );
    others.forEach(function (o) { if (o !== t) o.checked = false; });
  }

  function init() {
    mark();
    document.addEventListener("change", onToggle);
  }

  if (document.readyState !== "loading") init();
  else document.addEventListener("DOMContentLoaded", init);
})();
