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