import { defineComponent as B, ref as E, watch as N, onMounted as I, openBlock as l, createElementBlock as a, renderSlot as g, createElementVNode as V, createVNode as F, withCtx as u, Fragment as d, renderList as h, unref as i, toDisplayString as L, createBlock as f, createCommentVNode as b } from "vue";
import v from "./SidebarElement.vue.js";
import m from "./SidebarGroup.vue.js";
import { useSidebar as G } from "../../hooks/useSidebar.js";
import { sleep as w } from "../../helpers/sleep.js";
import { useNavState as x } from "../../hooks/useNavState.js";
const D = { class: "sidebar" }, H = { class: "sidebar-group-title" }, M = -160, P = /* @__PURE__ */ B({
  __name: "Sidebar",
  props: {
    parsedSpec: {}
  },
  setup(C) {
    const A = C, { hash: o, isIntersectionEnabled: $ } = x(), { items: O, toggleCollapsedSidebarItem: S, collapsedSidebarItems: T } = G(
      {
        parsedSpec: A.parsedSpec
      }
    ), y = E(null), c = E(!0);
    N(o, (p) => {
      !$.value || c.value || typeof window > "u" || k(p);
    });
    const k = (p) => {
      var t, r, s, _;
      const n = document.getElementById(`sidebar-${p}`);
      if (!n || !y.value) return;
      let e = M;
      n.getAttribute("data-sidebar-type") === "heading" ? e += n.offsetTop + ((t = n.getElementsByClassName("sidebar-heading")) == null ? void 0 : t[0]).offsetHeight : e += n.offsetTop + (((r = n.parentElement) == null ? void 0 : r.offsetTop) ?? 0) + (((_ = (s = n.parentElement) == null ? void 0 : s.parentElement) == null ? void 0 : _.offsetTop) ?? 0), y.value.scrollTo({ top: e, behavior: "smooth" });
    };
    return I(() => {
      setTimeout(() => k(o.value), 500), c.value = !1;
    }), (p, n) => (l(), a("div", D, [
      g(p.$slots, "sidebar-start", {}, void 0, !0),
      V("div", {
        ref_key: "scrollerEl",
        ref: y,
        class: "sidebar-pages custom-scroll custom-scroll-self-contain-overflow"
      }, [
        F(m, { level: 0 }, {
          default: u(() => [
            (l(!0), a(d, null, h(i(O).entries, (e) => (l(), a(d, {
              key: e.id
            }, [
              e.isGroup ? (l(), a(d, { key: 0 }, [
                V("li", H, L(e.displayTitle ?? e.title), 1),
                (l(!0), a(d, null, h(e.children, (t) => (l(), f(v, {
                  key: t.id,
                  id: `sidebar-${t.id}`,
                  "data-sidebar-type": "heading",
                  hasChildren: t.children && t.children.length > 0,
                  isActive: i(o) === t.id,
                  item: {
                    id: t.id,
                    title: t.displayTitle ?? t.title,
                    select: t.select,
                    httpVerb: t.httpVerb,
                    deprecated: t.deprecated ?? !1
                  },
                  open: i(T)[t.id] ?? !1,
                  onToggleOpen: async () => {
                    c.value = !0, i(S)(t.id), await i(w)(100), c.value = !1;
                  }
                }, {
                  default: u(() => {
                    var r;
                    return [
                      t.children && ((r = t.children) == null ? void 0 : r.length) > 0 ? (l(), f(m, {
                        key: 0,
                        level: 1
                      }, {
                        default: u(() => [
                          (l(!0), a(d, null, h(t.children, (s) => (l(), a(d, {
                            key: s.id
                          }, [
                            e.show ? (l(), f(v, {
                              key: 0,
                              id: `sidebar-${s.id}`,
                              isActive: i(o) === s.id,
                              item: {
                                id: s.id,
                                title: s.displayTitle ?? s.title,
                                select: s.select,
                                httpVerb: s.httpVerb,
                                deprecated: s.deprecated ?? !1
                              }
                            }, null, 8, ["id", "isActive", "item"])) : b("", !0)
                          ], 64))), 128))
                        ]),
                        _: 2
                      }, 1024)) : b("", !0)
                    ];
                  }),
                  _: 2
                }, 1032, ["id", "hasChildren", "isActive", "item", "open", "onToggleOpen"]))), 128))
              ], 64)) : (l(), a(d, { key: 1 }, [
                e.show ? (l(), f(v, {
                  key: 0,
                  id: `sidebar-${e.id}`,
                  "data-sidebar-type": "heading",
                  hasChildren: e.children && e.children.length > 0,
                  isActive: i(o) === e.id,
                  item: {
                    id: e.id,
                    title: e.displayTitle ?? e.title,
                    select: e.select,
                    httpVerb: e.httpVerb,
                    deprecated: e.deprecated ?? !1
                  },
                  open: i(T)[e.id] ?? !1,
                  onToggleOpen: async () => {
                    c.value = !0, i(S)(e.id), await i(w)(100), c.value = !1;
                  }
                }, {
                  default: u(() => {
                    var t;
                    return [
                      e.children && ((t = e.children) == null ? void 0 : t.length) > 0 ? (l(), f(m, {
                        key: 0,
                        level: 1
                      }, {
                        default: u(() => [
                          (l(!0), a(d, null, h(e.children, (r) => (l(), a(d, {
                            key: r.id
                          }, [
                            e.show ? (l(), f(v, {
                              key: 0,
                              id: `sidebar-${r.id}`,
                              isActive: i(o) === r.id,
                              item: {
                                id: r.id,
                                title: r.displayTitle ?? r.title,
                                select: r.select,
                                httpVerb: r.httpVerb,
                                deprecated: r.deprecated ?? !1
                              }
                            }, null, 8, ["id", "isActive", "item"])) : b("", !0)
                          ], 64))), 128))
                        ]),
                        _: 2
                      }, 1024)) : b("", !0)
                    ];
                  }),
                  _: 2
                }, 1032, ["id", "hasChildren", "isActive", "item", "open", "onToggleOpen"])) : b("", !0)
              ], 64))
            ], 64))), 128))
          ]),
          _: 1
        })
      ], 512),
      g(p.$slots, "sidebar-end", {}, void 0, !0)
    ]));
  }
});
export {
  P as default
};
