import { defineComponent as J, defineAsyncComponent as X, ref as O, onBeforeMount as Z, onMounted as _, computed as U, watch as x, onServerPrefetch as ee, useSSRContext as oe, getCurrentInstance as te, provide as A, openBlock as f, createElementBlock as h, Fragment as P, createVNode as p, unref as a, withCtx as i, createElementVNode as m, normalizeClass as re, normalizeStyle as ae, renderSlot as l, normalizeProps as d, guardReactiveProps as u, createCommentVNode as w, withDirectives as ne, vShow as se, createSlots as ie, createBlock as B } from "vue";
import { provideUseId as le } from "@headlessui/vue";
import "@scalar/components/style.css";
import { defaultStateFactory as de } from "@scalar/oas-utils/helpers";
import { ThemeStyles as ue, ResetStyles as ce, ScrollbarStyles as pe } from "@scalar/themes";
import "@scalar/themes/style.css";
import { ScalarToasts as fe } from "@scalar/use-toasts";
import { useMediaQuery as me, useResizeObserver as ge, useDebounceFn as Se } from "@vueuse/core";
import { NEW_API_MODAL as M } from "../features.js";
import ve from "./ApiClientModal.vue.js";
import he from "./GettingStarted.vue.js";
import { downloadSpecBus as be, downloadSpecFile as we } from "../helpers/specDownloads.js";
import { useDeprecationWarnings as ye } from "../hooks/useDeprecationWarnings.js";
import $e from "./Sidebar/Sidebar.vue.js";
import Re from "./Content/Content.vue.js";
import { useSidebar as Ce } from "../hooks/useSidebar.js";
import { GLOBAL_SECURITY_SYMBOL as Te, HIDE_DOWNLOAD_BUTTON_SYMBOL as ke } from "../helpers/provideSymbols.js";
import { useNavState as Ie } from "../hooks/useNavState.js";
import { scrollToId as De } from "../helpers/scrollToId.js";
import { sleep as Ee } from "../helpers/sleep.js";
const Fe = { class: "references-header" }, Le = {
  key: 0,
  class: "references-navigation t-doc__sidebar"
}, Oe = { class: "references-navigation-list" }, Ue = { class: "references-editor" }, Ae = { class: "references-editor-textarea" }, Pe = { class: "references-rendered" }, Be = {
  key: 0,
  class: "references-footer"
}, ro = /* @__PURE__ */ J({
  inheritAttrs: !1,
  __name: "ApiReferenceLayout",
  props: {
    configuration: {},
    parsedSpec: {},
    rawSpec: {}
  },
  emits: ["changeTheme", "updateContent", "loadSwaggerFile", "linkSwaggerFile", "toggleDarkMode"],
  setup(N) {
    const t = N, z = X(() => M ? (
      // Empty component
      new Promise((e) => {
        e({ render: () => null });
      })
    ) : (
      // Load component
      import("./ApiClientModalOld.vue.js")
    )), Y = me("(min-width: 1150px)"), y = O("100dvh"), b = O(null);
    ge(b, (e) => {
      y.value = e[0].contentRect.height + "px";
    });
    const {
      breadcrumb: H,
      collapsedSidebarItems: S,
      isSidebarOpen: V,
      setCollapsedSidebarItem: $,
      hideModels: W,
      setParsedSpec: G
    } = Ce(), {
      getPathRoutingId: R,
      getSectionId: j,
      getTagId: K,
      hash: C,
      isIntersectionEnabled: T,
      pathRouting: k,
      updateHash: I
    } = Ie();
    k.value = t.configuration.pathRouting, Z(() => I());
    const D = async (e) => {
      var o;
      T.value = !1, I(), e ? De(e) : (o = b.value) == null || o.scrollTo(0, 0), await Ee(100), T.value = !0;
    };
    _(() => {
      be.on(({ specTitle: e }) => {
        we(t.rawSpec, e);
      }), window.onhashchange = () => D(decodeURIComponent(window.location.hash.replace(/^#/, ""))), window.onpopstate = () => k.value && D(R(window.location.pathname));
    });
    const Q = U(
      () => Y.value || !t.configuration.isEditable
    ), E = Se((e) => {
      if ((e.target.scrollTop ?? 0) < 50) {
        const r = t.configuration.pathRouting ? t.configuration.pathRouting.basePath : window.location.pathname;
        window.history.replaceState({}, "", r + window.location.search), C.value = "";
      }
    }), s = U(() => ({
      breadcrumb: H.value,
      spec: t.parsedSpec
    }));
    return x(() => t.parsedSpec, G, { deep: !0 }), ee(() => {
      var o, r;
      const e = oe();
      if (e && ((o = e.payload).data || (o.data = de()), t.configuration.pathRouting)) {
        const n = R(e.url);
        C.value = n, e.payload.data.hash = n;
        for (const c in S)
          Object.hasOwn(S, c) && delete S[c];
        if (n)
          $(j(n), !0);
        else {
          const c = (r = t.parsedSpec.tags) == null ? void 0 : r[0];
          c && $(K(c), !0);
        }
        e.payload.data["useSidebarContent-collapsedSidebarItems"] = S;
      }
    }), le(() => {
      var n;
      const e = te(), o = "scalar-instance-id";
      if (!e) return o;
      let r = e.uid;
      return typeof window > "u" ? (e.attrs || (e.attrs = {}), e.attrs[o] = r) : (n = e.vnode.el) != null && n.getAttribute && (r = e.vnode.el.getAttribute(o)), `${o}-${r}`;
    }), A(Te, () => t.parsedSpec.security), A(
      ke,
      () => t.configuration.hideDownloadButton
    ), W.value = t.configuration.hideModels ?? !1, ye(t.configuration), (e, o) => {
      var r, n;
      return f(), h(P, null, [
        p(a(ue), {
          id: (r = e.configuration) == null ? void 0 : r.theme,
          withDefaultFonts: (n = e.configuration) == null ? void 0 : n.withDefaultFonts
        }, null, 8, ["id", "withDefaultFonts"]),
        p(a(ce), null, {
          default: i(({ styles: c }) => [
            p(a(pe), null, {
              default: i(({ styles: q }) => {
                var F, L;
                return [
                  m("div", {
                    ref_key: "documentEl",
                    ref: b,
                    class: re(["scalar-api-reference references-layout", [
                      {
                        "references-editable": e.configuration.isEditable,
                        "references-sidebar": e.configuration.showSidebar,
                        "references-sidebar-mobile-open": a(V),
                        "references-classic": e.configuration.layout === "classic"
                      },
                      c,
                      q,
                      e.$attrs.class
                    ]]),
                    style: ae({ "--full-height": y.value }),
                    onScrollPassive: o[4] || (o[4] = //@ts-ignore
                    (...v) => a(E) && a(E)(...v))
                  }, [
                    m("div", Fe, [
                      l(e.$slots, "header", d(u(s.value)), void 0, !0)
                    ]),
                    e.configuration.showSidebar ? (f(), h("aside", Le, [
                      m("div", Oe, [
                        p(a($e), { parsedSpec: e.parsedSpec }, {
                          "sidebar-start": i(() => [
                            l(e.$slots, "sidebar-start", d(u(s.value)), void 0, !0)
                          ]),
                          "sidebar-end": i(() => [
                            l(e.$slots, "sidebar-end", d(u(s.value)), void 0, !0)
                          ]),
                          _: 3
                        }, 8, ["parsedSpec"])
                      ])
                    ])) : w("", !0),
                    ne(m("div", Ue, [
                      m("div", Ae, [
                        l(e.$slots, "editor", d(u(s.value)), void 0, !0)
                      ])
                    ], 512), [
                      [se, e.configuration.isEditable]
                    ]),
                    Q.value ? (f(), h(P, { key: 1 }, [
                      m("div", Pe, [
                        p(a(Re), {
                          baseServerURL: e.configuration.baseServerURL,
                          layout: e.configuration.layout === "classic" ? "accordion" : "default",
                          parsedSpec: e.parsedSpec,
                          proxy: e.configuration.proxy,
                          servers: e.configuration.servers
                        }, ie({
                          start: i(() => [
                            l(e.$slots, "content-start", d(u(s.value)), void 0, !0)
                          ]),
                          end: i(() => [
                            l(e.$slots, "content-end", d(u(s.value)), void 0, !0)
                          ]),
                          _: 2
                        }, [
                          (F = e.configuration) != null && F.isEditable ? {
                            name: "empty-state",
                            fn: i(() => {
                              var v;
                              return [
                                p(he, {
                                  theme: ((v = e.configuration) == null ? void 0 : v.theme) || "default",
                                  onChangeTheme: o[0] || (o[0] = (g) => e.$emit("changeTheme", g)),
                                  onLinkSwaggerFile: o[1] || (o[1] = (g) => e.$emit("linkSwaggerFile")),
                                  onLoadSwaggerFile: o[2] || (o[2] = (g) => e.$emit("loadSwaggerFile")),
                                  onUpdateContent: o[3] || (o[3] = (g) => e.$emit("updateContent", g))
                                }, null, 8, ["theme"])
                              ];
                            }),
                            key: "0"
                          } : void 0
                        ]), 1032, ["baseServerURL", "layout", "parsedSpec", "proxy", "servers"])
                      ]),
                      e.$slots.footer ? (f(), h("div", Be, [
                        l(e.$slots, "footer", d(u(s.value)), void 0, !0)
                      ])) : w("", !0)
                    ], 64)) : w("", !0),
                    a(M) ? (f(), B(ve, {
                      key: 2,
                      proxyUrl: e.configuration.proxy,
                      spec: e.configuration.spec
                    }, null, 8, ["proxyUrl", "spec"])) : (f(), B(a(z), {
                      key: 3,
                      parsedSpec: e.parsedSpec,
                      proxyUrl: (L = e.configuration) == null ? void 0 : L.proxy
                    }, {
                      "sidebar-start": i(() => [
                        l(e.$slots, "sidebar-start", d(u(s.value)), void 0, !0)
                      ]),
                      "sidebar-end": i(() => [
                        l(e.$slots, "sidebar-end", d(u(s.value)), void 0, !0)
                      ]),
                      _: 3
                    }, 8, ["parsedSpec", "proxyUrl"]))
                  ], 38)
                ];
              }),
              _: 2
            }, 1024)
          ]),
          _: 3
        }),
        p(a(fe))
      ], 64);
    };
  }
});
export {
  ro as default
};
