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