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