import { defineComponent as A, openBlock as s, createElementBlock as p, createElementVNode as r, normalizeClass as T, unref as c, withModifiers as V, createVNode as v, withCtx as E, createTextVNode as h, toDisplayString as u, createCommentVNode as l, createBlock as N, renderSlot as C } from "vue";
import { ScalarSidebarGroupToggle as O, ScalarIcon as R } from "@scalar/components";
import { combineUrlAndPath as U } from "@scalar/oas-utils/helpers";
import { useConfig as H } from "../../hooks/useConfig.js";
import I from "./SidebarHttpBadge.vue.js";
import { sleep as k } from "../../helpers/sleep.js";
import { useNavState as P } from "../../hooks/useNavState.js";
import { scrollToId as D } from "../../helpers/scrollToId.js";
const L = ["id"], M = {
  key: 0,
  class: "sidebar-heading-chevron"
}, z = ["aria-expanded"], F = ["href", "tabindex"], G = { class: "sidebar-heading-link-title" }, j = {
  key: 1,
  class: "sidebar-heading-link-method"
}, q = {
  key: 1,
  class: "action-menu"
}, x = /* @__PURE__ */ A({
  __name: "SidebarElement",
  props: {
    id: {},
    item: {},
    isActive: { type: Boolean },
    hasChildren: { type: Boolean },
    open: { type: Boolean }
  },
  emits: ["toggleOpen"],
  setup(y, { emit: w }) {
    const i = y, m = w, { getFullHash: f, isIntersectionEnabled: d, replaceUrlState: S } = P(), n = H(), g = async () => {
      var e, t;
      d.value = !1, i.hasChildren && m("toggleOpen"), (t = (e = i.item) == null ? void 0 : e.select) == null || t.call(e), await k(100), d.value = !0;
    }, B = () => {
      if (n.value.pathRouting)
        return U(n.value.pathRouting.basePath, i.item.id);
      if (typeof window < "u") {
        const e = new URL(window.location.href);
        return e.hash = f(i.item.id), `${e.pathname}${e.search}${e.hash}`;
      }
      return `#${f(i.item.id)}`;
    }, $ = async (e) => {
      var t, a, o, b;
      (a = (t = n.value).onSidebarClick) == null || a.call(t, i.item.id), n.value.pathRouting && (e.preventDefault(), i.hasChildren && m("toggleOpen"), (b = (o = i.item) == null ? void 0 : o.select) == null || b.call(o), m("toggleOpen"), d.value = !1, S(i.item.id), D(i.item.id), await k(100), d.value = !0);
    };
    return (e, t) => {
      var a, o;
      return s(), p("li", {
        id: e.id,
        class: "sidebar-group-item"
      }, [
        r("div", {
          class: T(["sidebar-heading", {
            "sidebar-group-item__folder": e.hasChildren,
            active_page: e.isActive,
            deprecated: e.item.deprecated ?? !1
          }]),
          onClick: g
        }, [
          e.hasChildren && !c(n).defaultOpenAllTags ? (s(), p("p", M, [
            r("button", {
              "aria-expanded": e.open,
              class: "toggle-nested-icon",
              type: "button",
              onClick: V(g, ["stop"])
            }, [
              v(c(O), { open: e.open }, {
                label: E(() => [
                  h(u(e.open ? "Collapse" : "Expand") + " " + u(e.item.title), 1)
                ]),
                _: 1
              }, 8, ["open"])
            ], 8, z),
            t[0] || (t[0] = h("   "))
          ])) : l("", !0),
          r("a", {
            class: "sidebar-heading-link",
            href: B(),
            tabindex: e.hasChildren ? -1 : 0,
            onClick: $
          }, [
            (o = (a = e.item) == null ? void 0 : a.icon) != null && o.src ? (s(), N(c(R), {
              key: 0,
              class: "sidebar-icon",
              icon: e.item.icon.src
            }, null, 8, ["icon"])) : l("", !0),
            r("p", G, u(e.item.title), 1),
            e.item.httpVerb && !e.hasChildren ? (s(), p("p", j, [
              t[1] || (t[1] = h("   ")),
              t[2] || (t[2] = r("span", { class: "sr-only" }, "HTTP Method: ", -1)),
              v(I, {
                active: e.isActive,
                method: e.item.httpVerb
              }, null, 8, ["active", "method"])
            ])) : l("", !0)
          ], 8, F)
        ], 2),
        e.open ? C(e.$slots, "default", { key: 0 }, void 0, !0) : l("", !0),
        e.$slots["action-menu"] ? (s(), p("div", q, [
          C(e.$slots, "action-menu", {}, void 0, !0)
        ])) : l("", !0)
      ], 8, L);
    };
  }
});
export {
  x as default
};
