import { defineComponent as A, createElementBlock as d, openBlock as n, createElementVNode as a, renderSlot as g, createCommentVNode as r, normalizeClass as O, unref as s, createTextVNode as m, withModifiers as T, createVNode as b, withCtx as v, toDisplayString as h, createBlock as $, normalizeStyle as E } from "vue";
import { ScalarSidebarGroupToggle as N } 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 { isOperationDeprecated as R, combineUrlAndPath as U } from "@scalar/oas-utils/helpers";
import { useConfig as D } 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"
}, j = ["aria-expanded"], F = ["href", "tabindex"], G = { class: "sidebar-heading-link-title" }, W = {
  key: 0,
  class: "sidebar-heading-link-method"
}, q = {
  key: 1,
  class: "action-menu"
}, oe = /* @__PURE__ */ A({
  __name: "SidebarElement",
  props: {
    id: {},
    item: {},
    isActive: { type: Boolean },
    hasChildren: { type: Boolean },
    open: { type: Boolean }
  },
  emits: ["toggleOpen"],
  setup(C, { emit: y }) {
    const o = C, p = y, { getFullHash: u, isIntersectionEnabled: l, replaceUrlState: w } = L(), i = D(), c = async () => {
      l.value = !1, o.hasChildren && p("toggleOpen"), await k(100), l.value = !0;
    }, S = () => {
      if (i.value.pathRouting)
        return U(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.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 && p("toggleOpen"), p("toggleOpen"), l.value = !1, w(o.item.id), V(o.item.id), await k(100), l.value = !0);
    };
    return (e, t) => (n(), d("li", {
      id: e.id,
      class: "sidebar-group-item"
    }, [
      a("div", {
        class: O(["sidebar-heading", {
          "sidebar-group-item__folder": e.hasChildren,
          active_page: e.isActive,
          deprecated: "operation" in e.item && s(R)(
            e.item.operation
          )
        }]),
        onClick: c
      }, [
        e.hasChildren && !s(i).defaultOpenAllTags ? (n(), d("p", z, [
          a("button", {
            "aria-expanded": e.open,
            class: "toggle-nested-icon",
            type: "button",
            onClick: T(c, ["stop"])
          }, [
            b(s(N), { open: e.open }, {
              label: v(() => [
                m(h(e.open ? "Collapse" : "Expand") + " " + h(e.item.title), 1)
              ]),
              _: 1
            }, 8, ["open"])
          ], 8, j),
          t[0] || (t[0] = m("   "))
        ])) : 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(), d("p", W, [
            t[1] || (t[1] = m("   ")),
            t[2] || (t[2] = a("span", { class: "sr-only" }, "HTTP Method: ", -1)),
            b(M, {
              class: "min-w-9.75 justify-end text-right",
              active: e.isActive,
              method: e.item.method
            }, {
              default: v(() => [
                "webhook" in e.item ? (n(), $(s(I), {
                  key: 0,
                  weight: "bold",
                  style: E({
                    color: s(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(), d("div", q, [
        g(e.$slots, "action-menu", {}, void 0, !0)
      ])) : r("", !0)
    ], 8, P));
  }
});
export {
  oe as default
};
