import { defineComponent as Q, inject as W, computed as p, createBlock as n, createCommentVNode as d, openBlock as i, unref as u, withCtx as v, createElementVNode as I, normalizeClass as M, createElementBlock as t, withDirectives as E, createVNode as h, createTextVNode as P, toDisplayString as H, vShow as R, normalizeStyle as Y, Fragment as m, renderList as $ } from "vue";
import { Disclosure as Z, DisclosureButton as F, DisclosurePanel as _ } from "@headlessui/vue";
import { ScalarMarkdown as x, ScalarIcon as V } from "@scalar/components";
import L from "../../ScreenReader.vue.js";
import { DISCRIMINATOR_CONTEXT as ee } from "../../../hooks/useDiscriminator.js";
import ae from "./SchemaHeading.vue.js";
import b from "./SchemaProperty.vue.js";
const ie = {
  key: 0,
  class: "schema-card-description"
}, le = {
  key: 0,
  class: "schema-properties"
}, ue = /* @__PURE__ */ Q({
  __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 }
  },
  emits: ["update:modelValue"],
  setup(X, { emit: G }) {
    const o = X, J = G, r = W(ee, null), y = p(
      () => {
        var e;
        return ((e = r == null ? void 0 : r.value) == null ? void 0 : e.discriminatorMapping) || o.discriminatorMapping || {};
      }
    ), c = p(
      () => {
        var e;
        return ((e = r == null ? void 0 : r.value) == null ? void 0 : e.discriminatorPropertyName) || o.discriminatorPropertyName || "";
      }
    ), D = p(
      () => {
        var e;
        return ((e = r == null ? void 0 : r.value) == null ? void 0 : e.selectedType) || o.discriminator;
      }
    ), O = (e) => e !== null && typeof e == "object" && "type" in e && e.type === "object", a = p(() => {
      var s;
      const e = (s = r == null ? void 0 : r.value) == null ? void 0 : s.mergedSchema, S = o.value;
      return e && o.level === 0 && o.hasDiscriminator && O(S) && O(e) ? e : o.value;
    }), j = p(() => !(o.noncollapsible || o.level === 0)), K = p(() => {
      var e;
      return !(!((e = a.value) != null && e.description) || typeof a.value.description != "string" || a.value.allOf || a.value.oneOf || a.value.anyOf || a.value.enum || o.level === 0);
    }), B = (e) => o.noncollapsible && e.stopPropagation(), g = (e) => {
      J("update:modelValue", e);
    };
    return (e, S) => typeof e.value == "object" && Object.keys(e.value).length ? (i(), n(u(Z), {
      key: 0,
      defaultOpen: e.noncollapsible
    }, {
      default: v(({ open: s }) => {
        var w, C;
        return [
          I("div", {
            class: M(["schema-card", [
              `schema-card--level-${e.level}`,
              { "schema-card--compact": e.compact, "schema-card--open": s },
              { "border-t": e.additionalProperties && s }
            ]])
          }, [
            K.value ? (i(), t("div", ie, [
              (w = a.value) != null && w.enum ? d("", !0) : (i(), n(u(x), {
                key: 0,
                value: (C = a.value) == null ? void 0 : C.description
              }, null, 8, ["value"]))
            ])) : d("", !0),
            I("div", {
              class: M(["schema-properties", {
                "schema-properties-open": s
              }])
            }, [
              e.additionalProperties ? E((i(), t("div", le, [
                h(u(F), {
                  as: "button",
                  class: "schema-card-title schema-card-title--compact",
                  onClickCapture: B
                }, {
                  default: v(() => [
                    h(u(V), {
                      class: "schema-card-title-icon",
                      icon: "Add",
                      size: "sm"
                    }),
                    S[0] || (S[0] = P(" Show additional properties ")),
                    e.name ? (i(), n(L, { key: 0 }, {
                      default: v(() => [
                        P("for " + H(e.name), 1)
                      ]),
                      _: 1
                    })) : d("", !0)
                  ]),
                  _: 1
                })
              ], 512)), [
                [R, !s]
              ]) : j.value ? E((i(), n(u(F), {
                key: 1,
                as: e.noncollapsible ? "div" : "button",
                class: M(["schema-card-title", { "schema-card-title--compact": e.compact }]),
                style: Y({
                  top: `calc(var(--refs-header-height) +  calc(var(--schema-title-height) * ${e.level}))`
                }),
                onClickCapture: B
              }, {
                default: v(() => {
                  var f, N, l;
                  return [
                    e.compact ? (i(), t(m, { key: 0 }, [
                      h(u(V), {
                        class: M(["schema-card-title-icon", { "schema-card-title-icon--open": s }]),
                        icon: "Add",
                        size: "sm"
                      }, null, 8, ["class"]),
                      s ? (i(), t(m, { key: 0 }, [
                        P(" Hide " + H(((f = e.value) == null ? void 0 : f.title) ?? "Child Attributes"), 1)
                      ], 64)) : (i(), t(m, { key: 1 }, [
                        P(" Show " + H(((N = e.value) == null ? void 0 : N.title) ?? "Child Attributes"), 1)
                      ], 64)),
                      e.name ? (i(), n(L, { key: 2 }, {
                        default: v(() => [
                          P("for " + H(e.name), 1)
                        ]),
                        _: 1
                      })) : d("", !0)
                    ], 64)) : (i(), t(m, { key: 1 }, [
                      h(u(V), {
                        class: M(["schema-card-title-icon", { "schema-card-title-icon--open": s }]),
                        icon: "Add",
                        size: "sm"
                      }, null, 8, ["class"]),
                      h(ae, {
                        name: ((l = e.value) == null ? void 0 : l.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),
              h(u(_), {
                as: "ul",
                static: !j.value
              }, {
                default: v(() => {
                  var f, N;
                  return [
                    a.value && typeof a.value == "object" && ("properties" in a.value || "additionalProperties" in a.value || "patternProperties" in a.value) ? (i(), t(m, { key: 0 }, [
                      a.value.properties ? (i(!0), t(m, { key: 0 }, $(Object.keys(a.value.properties), (l) => {
                        var k, A, T, z, U, q;
                        return i(), n(b, {
                          key: l,
                          compact: e.compact,
                          hideHeading: e.hideHeading,
                          level: e.level + 1,
                          name: l,
                          hideModelNames: e.hideModelNames,
                          required: ((k = a.value.required) == null ? void 0 : k.includes(l)) || ((A = a.value.properties[l]) == null ? void 0 : A.required) === !0,
                          schemas: e.schemas,
                          resolvedSchema: a.value.properties[l],
                          value: {
                            ...a.value.properties[l],
                            parent: a.value,
                            isDiscriminator: l === c.value || ((T = a.value.discriminator) == null ? void 0 : T.propertyName) === l
                          },
                          discriminatorMapping: ((z = a.value.discriminator) == null ? void 0 : z.mapping) || y.value,
                          discriminatorPropertyName: ((U = a.value.discriminator) == null ? void 0 : U.propertyName) || c.value,
                          isDiscriminator: l === (((q = a.value.discriminator) == null ? void 0 : q.propertyName) || c.value),
                          modelValue: D.value,
                          "onUpdate:modelValue": g
                        }, null, 8, ["compact", "hideHeading", "level", "name", "hideModelNames", "required", "schemas", "resolvedSchema", "value", "discriminatorMapping", "discriminatorPropertyName", "isDiscriminator", "modelValue"]);
                      }), 128)) : d("", !0),
                      a.value.patternProperties ? (i(!0), t(m, { key: 1 }, $(Object.keys(a.value.patternProperties), (l) => {
                        var k;
                        return i(), n(b, {
                          key: l,
                          compact: e.compact,
                          hideHeading: e.hideHeading,
                          level: e.level,
                          name: l,
                          hideModelNames: e.hideModelNames,
                          pattern: "",
                          schemas: e.schemas,
                          value: ((k = e.value.discriminator) == null ? void 0 : k.propertyName) === l ? e.value : a.value.patternProperties[l],
                          discriminatorMapping: y.value,
                          discriminatorPropertyName: c.value,
                          "onUpdate:modelValue": g
                        }, null, 8, ["compact", "hideHeading", "level", "name", "hideModelNames", "schemas", "value", "discriminatorMapping", "discriminatorPropertyName"]);
                      }), 128)) : d("", !0),
                      a.value.additionalProperties ? (i(), t(m, { key: 2 }, [
                        a.value.additionalProperties === !0 || Object.keys(a.value.additionalProperties).length === 0 || !("type" in a.value.additionalProperties) ? (i(), n(b, {
                          key: 0,
                          additional: "",
                          compact: e.compact,
                          hideHeading: e.hideHeading,
                          hideModelNames: e.hideModelNames,
                          level: e.level,
                          noncollapsible: "",
                          schemas: e.schemas,
                          value: {
                            type: "anything",
                            ...typeof a.value.additionalProperties == "object" ? a.value.additionalProperties : {}
                          },
                          discriminatorMapping: y.value,
                          discriminatorPropertyName: c.value,
                          "onUpdate:modelValue": g
                        }, null, 8, ["compact", "hideHeading", "hideModelNames", "level", "schemas", "value", "discriminatorMapping", "discriminatorPropertyName"])) : (i(), n(b, {
                          key: 1,
                          additional: "",
                          compact: e.compact,
                          hideHeading: e.hideHeading,
                          hideModelNames: e.hideModelNames,
                          level: e.level,
                          noncollapsible: "",
                          schemas: e.schemas,
                          value: ((f = e.value.discriminator) == null ? void 0 : f.propertyName) === e.name ? e.value : a.value.additionalProperties,
                          discriminatorMapping: y.value,
                          discriminatorPropertyName: c.value,
                          "onUpdate:modelValue": g
                        }, null, 8, ["compact", "hideHeading", "hideModelNames", "level", "schemas", "value", "discriminatorMapping", "discriminatorPropertyName"]))
                      ], 64)) : d("", !0)
                    ], 64)) : (i(), t(m, { key: 1 }, [
                      a.value ? (i(), n(b, {
                        key: 0,
                        compact: e.compact,
                        hideHeading: e.hideHeading,
                        hideModelNames: e.hideModelNames,
                        level: e.level,
                        name: a.value.name,
                        schemas: e.schemas,
                        value: ((N = e.value.discriminator) == null ? void 0 : N.propertyName) === e.name ? e.value : a.value,
                        discriminatorMapping: y.value,
                        discriminatorPropertyName: c.value,
                        modelValue: D.value,
                        "onUpdate:modelValue": g
                      }, null, 8, ["compact", "hideHeading", "hideModelNames", "level", "name", "schemas", "value", "discriminatorMapping", "discriminatorPropertyName", "modelValue"])) : d("", !0)
                    ], 64))
                  ];
                }),
                _: 1
              }, 8, ["static"])
            ], 2)
          ], 2)
        ];
      }),
      _: 1
    }, 8, ["defaultOpen"])) : d("", !0);
  }
});
export {
  ue as default
};
