import { defineComponent as I, inject as E, computed as u, createBlock as c, createCommentVNode as d, openBlock as i, unref as s, withCtx as p, createElementVNode as C, normalizeClass as v, createElementBlock as m, createVNode as h, withDirectives as w, createTextVNode as f, toDisplayString as g, vShow as R, normalizeStyle as $, Fragment as y } from "vue";
import { Disclosure as U, DisclosureButton as T, DisclosurePanel as X } from "@headlessui/vue";
import { ScalarMarkdown as G, ScalarIcon as b } from "@scalar/components";
import j from "../../ScreenReader.vue.js";
import { useConfig as J } from "../../../hooks/useConfig.js";
import { DISCRIMINATOR_CONTEXT as K } from "../../../hooks/useDiscriminator.js";
import { isTypeObject as P } from "./helpers/is-type-object.js";
import L from "./SchemaHeading.vue.js";
import Q from "./SchemaObjectProperties.vue.js";
import Y from "./SchemaProperty.vue.js";
const Z = {
  key: 0,
  class: "schema-card-description"
}, W = {
  key: 0,
  class: "schema-properties"
}, ne = /* @__PURE__ */ I({
  __name: "Schema",
  props: {
    value: { type: [Object, Boolean] },
    level: { default: 0 },
    name: {},
    compact: { type: Boolean },
    noncollapsible: { type: Boolean, default: !1 },
    hideHeading: { type: Boolean },
    additionalProperties: { type: Boolean },
    hideModelNames: { type: Boolean, default: !1 },
    schemas: {},
    discriminator: {},
    discriminatorMapping: {},
    discriminatorPropertyName: {},
    hasDiscriminator: { type: Boolean },
    breadcrumb: {}
  },
  emits: ["update:modelValue"],
  setup(z, { emit: q }) {
    const l = z, F = q, k = J(), o = E(K, null), N = u(
      () => {
        var e;
        return ((e = o == null ? void 0 : o.value) == null ? void 0 : e.discriminatorMapping) || l.discriminatorMapping || {};
      }
    ), S = u(
      () => {
        var e;
        return ((e = o == null ? void 0 : o.value) == null ? void 0 : e.discriminatorPropertyName) || l.discriminatorPropertyName || "";
      }
    ), M = u(
      () => {
        var e;
        return ((e = o == null ? void 0 : o.value) == null ? void 0 : e.selectedType) || l.discriminator;
      }
    ), a = u(() => {
      var r;
      const e = (r = o == null ? void 0 : o.value) == null ? void 0 : r.mergedSchema, n = l.value;
      return e && l.level === 0 && l.hasDiscriminator && P(n) && P(e) ? e : l.value;
    }), B = u(() => !(l.noncollapsible || l.level === 0)), D = u(() => {
      var e, n;
      if ((e = a.value) != null && e.allOf && Array.isArray(a.value.allOf) && // Because we don't want it to show in models
      l.name === "Request Body") {
        if (a.value.description)
          return a.value.description;
        const r = a.value.allOf.find(
          (t) => t.description && typeof t.description == "string"
        );
        if (r != null && r.description)
          return r.description;
      }
      return !((n = a.value) != null && n.description) || typeof a.value.description != "string" || a.value.oneOf || a.value.anyOf || a.value.enum || !a.value.properties && !a.value.patternProperties && !a.value.additionalProperties || l.level === 0 ? null : a.value.description;
    }), O = (e) => l.noncollapsible && e.stopPropagation(), H = (e) => {
      F("update:modelValue", e);
    };
    return (e, n) => typeof e.value == "object" && Object.keys(e.value).length ? (i(), c(s(U), {
      key: 0,
      defaultOpen: e.noncollapsible
    }, {
      default: p(({ open: r }) => [
        C("div", {
          class: v(["schema-card", [
            `schema-card--level-${e.level}`,
            { "schema-card--compact": e.compact, "schema-card--open": r },
            { "border-t": e.additionalProperties && r }
          ]])
        }, [
          D.value ? (i(), m("div", Z, [
            h(s(G), { value: D.value }, null, 8, ["value"])
          ])) : d("", !0),
          C("div", {
            class: v(["schema-properties", {
              "schema-properties-open": r
            }])
          }, [
            e.additionalProperties ? w((i(), m("div", W, [
              h(s(T), {
                as: "button",
                class: "schema-card-title schema-card-title--compact",
                onClickCapture: O
              }, {
                default: p(() => [
                  h(s(b), {
                    class: "schema-card-title-icon",
                    icon: "Add",
                    size: "sm"
                  }),
                  n[0] || (n[0] = f(" Show additional properties ")),
                  e.name ? (i(), c(j, { key: 0 }, {
                    default: p(() => [
                      f("for " + g(e.name), 1)
                    ]),
                    _: 1
                  })) : d("", !0)
                ]),
                _: 1,
                __: [0]
              })
            ], 512)), [
              [R, !r]
            ]) : B.value ? w((i(), c(s(T), {
              key: 1,
              as: e.noncollapsible ? "div" : "button",
              class: v(["schema-card-title", { "schema-card-title--compact": e.compact }]),
              style: $({
                top: `calc(var(--refs-header-height) +  calc(var(--schema-title-height) * ${e.level}))`
              }),
              onClickCapture: O
            }, {
              default: p(() => {
                var t, V, A;
                return [
                  e.compact ? (i(), m(y, { key: 0 }, [
                    h(s(b), {
                      class: v(["schema-card-title-icon", { "schema-card-title-icon--open": r }]),
                      icon: "Add",
                      size: "sm"
                    }, null, 8, ["class"]),
                    r ? (i(), m(y, { key: 0 }, [
                      f(" Hide " + g(((t = e.value) == null ? void 0 : t.title) ?? "Child Attributes"), 1)
                    ], 64)) : (i(), m(y, { key: 1 }, [
                      f(" Show " + g(((V = e.value) == null ? void 0 : V.title) ?? "Child Attributes"), 1)
                    ], 64)),
                    e.name ? (i(), c(j, { key: 2 }, {
                      default: p(() => [
                        f("for " + g(e.name), 1)
                      ]),
                      _: 1
                    })) : d("", !0)
                  ], 64)) : (i(), m(y, { key: 1 }, [
                    h(s(b), {
                      class: v(["schema-card-title-icon", { "schema-card-title-icon--open": r }]),
                      icon: "Add",
                      size: "sm"
                    }, null, 8, ["class"]),
                    h(L, {
                      name: ((A = e.value) == null ? void 0 : A.title) ?? e.name,
                      value: e.value
                    }, null, 8, ["name", "value"])
                  ], 64))
                ];
              }),
              _: 2
            }, 1032, ["as", "class", "style"])), [
              [R, !e.hideHeading && !(e.noncollapsible && e.compact)]
            ]) : d("", !0),
            !e.additionalProperties || r ? (i(), c(s(X), {
              key: 2,
              as: "ul",
              static: !B.value
            }, {
              default: p(() => {
                var t;
                return [
                  s(P)(a.value) ? (i(), c(Q, {
                    key: 0,
                    breadcrumb: e.breadcrumb,
                    compact: e.compact,
                    discriminator: M.value,
                    discriminatorMapping: N.value,
                    discriminatorPropertyName: S.value,
                    hasDiscriminator: e.hasDiscriminator,
                    hideHeading: e.hideHeading,
                    hideModelNames: e.hideModelNames,
                    level: e.level + 1,
                    orderRequiredPropertiesFirst: s(k).orderRequiredPropertiesFirst,
                    orderSchemaPropertiesBy: s(k).orderSchemaPropertiesBy,
                    schema: a.value,
                    schemas: e.schemas,
                    "onUpdate:modelValue": H
                  }, null, 8, ["breadcrumb", "compact", "discriminator", "discriminatorMapping", "discriminatorPropertyName", "hasDiscriminator", "hideHeading", "hideModelNames", "level", "orderRequiredPropertiesFirst", "orderSchemaPropertiesBy", "schema", "schemas"])) : (i(), m(y, { key: 1 }, [
                    a.value ? (i(), c(Y, {
                      key: 0,
                      breadcrumb: e.breadcrumb,
                      compact: e.compact,
                      discriminatorMapping: N.value,
                      discriminatorPropertyName: S.value,
                      hideHeading: e.hideHeading,
                      hideModelNames: e.hideModelNames,
                      level: e.level,
                      modelValue: M.value,
                      name: a.value.name,
                      schemas: e.schemas,
                      value: ((t = e.value.discriminator) == null ? void 0 : t.propertyName) === e.name ? e.value : a.value,
                      "onUpdate:modelValue": H
                    }, null, 8, ["breadcrumb", "compact", "discriminatorMapping", "discriminatorPropertyName", "hideHeading", "hideModelNames", "level", "modelValue", "name", "schemas", "value"])) : d("", !0)
                  ], 64))
                ];
              }),
              _: 1
            }, 8, ["static"])) : d("", !0)
          ], 2)
        ], 2)
      ]),
      _: 1
    }, 8, ["defaultOpen"])) : d("", !0);
  }
});
export {
  ne as default
};
