import { defineComponent as H, ref as v, watch as K, onMounted as j, withDirectives as A, createElementBlock as m, openBlock as a, normalizeClass as F, createBlock as p, createCommentVNode as b, Fragment as y, renderList as w, unref as o, withCtx as c, createVNode as _, createTextVNode as $, toDisplayString as q, vShow as G } from "vue";
import { scrollToId as T } from "@scalar/helpers/dom/scroll-to-id";
import { lazyBus as J } from "./lazyBus.js";
import { useNavState as P } from "../../../hooks/useNavState.js";
import { getModels as S } from "../../../libs/openapi.js";
import Q from "../Tag/TagSection.vue.js";
import R from "../../../features/Operation/Operation.vue.js";
import U from "../../Section/SectionContainer.vue.js";
import X from "../../Section/Section.vue.js";
import Y from "../../Section/SectionContent.vue.js";
import Z from "../../Section/SectionHeader.vue.js";
import O from "../../Anchor/Anchor.vue.js";
import ee from "../../Section/SectionHeaderTag.vue.js";
import te from "../Schema/Schema.vue.js";
const x = v(!1), he = /* @__PURE__ */ H({
  __name: "Loading",
  props: {
    document: {},
    collection: {},
    server: {},
    layout: { default: "modern" },
    parsedSpec: {}
  },
  setup(B) {
    const { document: h, collection: C, server: N, layout: z, parsedSpec: f } = B, L = v(!1), k = v([]), I = v([]), { getModelId: V, getSectionId: M, getTagId: D, hash: l, isIntersectionEnabled: g } = P(), W = v(!x.value && z !== "classic" && l.value);
    K(
      () => {
        var s;
        return (s = f.tags) == null ? void 0 : s.length;
      },
      (s) => {
        var e, u;
        if (!l.value || typeof s != "number" || !f.tags)
          return;
        const i = M();
        if (i.startsWith("tag")) {
          let t = 0;
          const d = ((e = f.tags) == null ? void 0 : e.findIndex((r) => D(r) === i)) ?? 0;
          t = (u = f.tags[d]) == null ? void 0 : u.operations.findIndex(
            ({ id: r }) => r === l.value
          );
          const n = f.tags[d];
          if (!n)
            return;
          n.name !== "default" && (L.value = i !== l.value && i.startsWith("tag")), k.value.push({
            ...n,
            lazyOperations: n.operations.slice(t, t + 2).map((r) => ({
              ...r,
              // Prefix the id with lazy- to avoid collisions with the real ids
              id: "lazy-" + r.id
            }))
          }), l.value.includes("/description/") && (typeof window < "u" && T(l.value), setTimeout(() => g.value = !0, 1e3));
        } else if (l.value.startsWith("model")) {
          const t = Object.keys(S(h) ?? {}), [, d] = l.value.toLowerCase().split("/"), n = l.value === "models" ? 0 : t.findIndex((r) => r.toLowerCase() === d);
          if (n === -1)
            return;
          I.value = t.slice(n, n + 3);
        } else
          typeof window < "u" && T(l.value), setTimeout(() => g.value = !0, 1e3);
      },
      { immediate: !0 }
    );
    const E = J.on(({ id: s }) => {
      const i = l.value;
      !i || s !== i || (E(), setTimeout(() => {
        typeof window < "u" && T(i), W.value = !1, x.value = !0, setTimeout(() => {
          g.value = !0;
        }, 1e3);
      }, 300));
    });
    return j(() => {
      l.value || (x.value = !0, setTimeout(() => {
        g.value = !0;
      }, 1e3));
    }), (s, i) => A((a(), m("div", {
      class: F(["references-loading", {
        "references-loading-hidden-tag": L.value,
        "references-loading-top-spacer": k.value.length
      }])
    }, [
      (a(!0), m(y, null, w(k.value, (e, u) => (a(), m(y, {
        key: e.name + u
      }, [
        e.operations && e.operations.length > 0 ? (a(), p(o(Q), {
          key: 0,
          collection: C,
          spec: f,
          id: "lazy-{{ getTagId(tag) }}",
          tag: e
        }, {
          default: c(() => [
            (a(!0), m(y, null, w(e.lazyOperations, (t) => (a(), p(o(R), {
              path: t.path,
              method: t.httpVerb,
              isWebhook: t.isWebhook,
              key: t.id,
              id: t.id,
              collection: C,
              layout: z,
              server: N
            }, null, 8, ["path", "method", "isWebhook", "id"]))), 128))
          ]),
          _: 2
        }, 1032, ["tag"])) : b("", !0)
      ], 64))), 128)),
      I.value.length ? (a(), p(o(U), { key: 0 }, {
        default: c(() => [
          (a(!0), m(y, null, w(I.value, (e) => (a(), p(o(X), {
            key: e,
            label: e
          }, {
            default: c(() => {
              var u;
              return [
                (u = o(S)(h)) != null && u[e] ? (a(), p(o(Y), { key: 0 }, {
                  default: c(() => {
                    var t;
                    return [
                      _(o(Z), null, {
                        default: c(() => [
                          _(o(O), {
                            id: "lazy-" + o(V)({ name: e })
                          }, {
                            default: c(() => [
                              _(o(ee), { level: 2 }, {
                                default: c(() => {
                                  var d;
                                  return [
                                    $(q(((d = o(S)(h)) == null ? void 0 : d[e]).title ?? e), 1)
                                  ];
                                }),
                                _: 2
                              }, 1024)
                            ]),
                            _: 2
                          }, 1032, ["id"])
                        ]),
                        _: 2
                      }, 1024),
                      _(o(te), {
                        name: e,
                        noncollapsible: "",
                        value: (t = o(S)(h)) == null ? void 0 : t[e]
                      }, null, 8, ["name", "value"])
                    ];
                  }),
                  _: 2
                }, 1024)) : b("", !0)
              ];
            }),
            _: 2
          }, 1032, ["label"]))), 128))
        ]),
        _: 1
      })) : b("", !0)
    ], 2)), [
      [G, W.value]
    ]);
  }
});
export {
  he as default
};
