import { defineComponent as W, computed as o, inject as Y, createBlock as h, openBlock as t, resolveDynamicComponent as _, normalizeClass as R, withCtx as f, createCommentVNode as l, createElementBlock as r, createVNode as m, createSlots as x, createTextVNode as B, toDisplayString as g, unref as p, Fragment as v, renderList as M, createElementVNode as k } from "vue";
import { Disclosure as ee, DisclosurePanel as ne, DisclosureButton as ie } from "@headlessui/vue";
import { ScalarMarkdown as O, ScalarIcon as te } from "@scalar/components";
import { optimizeValueForDisplay as ae, compositions as re } from "./helpers/optimizeValueForDisplay.js";
import { DISCRIMINATOR_CONTEXT as oe } from "../../../hooks/useDiscriminator.js";
import T from "./Schema.vue.js";
import U from "./SchemaComposition.vue.js";
import se from "./SchemaDiscriminator.vue.js";
import le from "./SchemaPropertyHeading.vue.js";
import me from "../../../features/specification-extension/SpecificationExtension.vue.js";
const pe = {
  key: 1,
  class: "property-description"
}, ce = {
  key: 2,
  class: "property-description"
}, de = {
  key: 3,
  class: "property-enum"
}, ue = {
  key: 0,
  class: "property-list"
}, ye = { class: "property-heading" }, he = { class: "property-name" }, fe = { class: "property-description" }, ge = {
  key: 1,
  class: "property-enum-values"
}, ve = { class: "property-enum-value-label" }, be = { class: "property-enum-value-label" }, ke = {
  key: 4,
  class: "children"
}, De = {
  key: 0,
  class: "children"
}, Ve = /* @__PURE__ */ W({
  __name: "SchemaProperty",
  props: {
    is: {},
    value: {},
    noncollapsible: { type: Boolean },
    level: { default: 0 },
    name: {},
    required: { type: Boolean, default: !1 },
    compact: { type: Boolean, default: !1 },
    description: {},
    additional: { type: Boolean },
    pattern: { type: Boolean },
    withExamples: { type: Boolean, default: !0 },
    hideModelNames: { type: Boolean, default: !1 },
    schemas: {},
    hideHeading: { type: Boolean },
    discriminatorMapping: {},
    discriminatorPropertyName: {},
    isDiscriminator: { type: Boolean }
  },
  emits: ["update:modelValue"],
  setup(q, { emit: F }) {
    const D = q, $ = F, E = {
      integer: {
        _default: "Integer numbers.",
        int32: "Signed 32-bit integers (commonly used integer type).",
        int64: "Signed 64-bit integers (long type)."
      },
      string: {
        date: "full-date notation as defined by RFC 3339, section 5.6, for example, 2017-07-21",
        "date-time": "the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z",
        password: "a hint to UIs to mask the input",
        base64: "base64-encoded characters, for example, U3dhZ2dlciByb2Nrcw==",
        byte: "base64-encoded characters, for example, U3dhZ2dlciByb2Nrcw==",
        binary: "binary data, used to describe files"
      }
    }, P = (e, n) => n != null && n.properties || n != null && n.additionalProperties || n != null && n.patternProperties || n != null && n.allOf ? null : e || (n == null ? void 0 : n.description) || null, C = (e) => !e || !E[e.type] ? null : E[e.type][e.format || e.contentEncoding || "_default"], u = (e) => {
      var n;
      return (e == null ? void 0 : e.enum) || ((n = e == null ? void 0 : e.items) == null ? void 0 : n.enum) || [];
    }, H = o(
      () => u(i.value).length > 9
    ), V = o(() => H.value ? 5 : 9), z = o(
      () => u(i.value).slice(0, V.value)
    ), L = o(
      () => u(i.value).slice(V.value)
    ), i = o(() => ae(D.value)), d = Y(oe, null), s = o(() => {
      var e;
      return D.level > 0 ? i.value : (e = d == null ? void 0 : d.value) != null && e.mergedSchema ? d.value.mergedSchema : i.value;
    }), Z = o(() => {
      var e;
      return ((e = d == null ? void 0 : d.value) == null ? void 0 : e.selectedType) || (D.discriminatorMapping ? Object.keys(D.discriminatorMapping)[0] : "");
    }), X = (e, n, y, N, S) => n || y || N || (e == null ? void 0 : e.deprecated) || (e == null ? void 0 : e.const) || (e == null ? void 0 : e.enum) && e.enum.length === 1 || (e == null ? void 0 : e.type) || (e == null ? void 0 : e.nullable) === !0 || (e == null ? void 0 : e.writeOnly) || (e == null ? void 0 : e.readOnly) || S, j = (e) => {
      $("update:modelValue", e);
    }, w = o(() => {
      const e = i.value;
      if (!(e != null && e.items) || typeof e.items != "object")
        return !1;
      const n = e.items;
      return "type" in n && ["object"].includes(n.type) || "$ref" in n || "discriminator" in n || "allOf" in n || "oneOf" in n || "anyOf" in n;
    }), G = (e) => {
      const n = i.value;
      return !(n != null && n.items) || typeof n.items != "object" || !(e in n.items) ? !1 : !w.value;
    }, J = o(() => w.value), K = o(() => {
      if (!i.value)
        return !1;
      const e = i.value, n = e.type === "object" || Array.isArray(e.type) && e.type.includes("object"), y = e.properties || e.additionalProperties;
      return n && y;
    }), Q = o(() => {
      var n;
      if (!((n = i.value) != null && n["x-enumDescriptions"]))
        return !1;
      const e = i.value["x-enumDescriptions"];
      return typeof e == "object" && !Array.isArray(e);
    });
    return (e, n) => {
      var y;
      return t(), h(_(e.is ?? "li"), {
        class: R(["property", [
          (P(e.description, i.value), ""),
          `property--level-${e.level}`,
          {
            "property--compact": e.compact,
            "property--deprecated": (y = i.value) == null ? void 0 : y.deprecated
          }
        ]])
      }, {
        default: f(() => {
          var N, S, A;
          return [
            X(
              i.value,
              e.name,
              e.additional,
              e.pattern,
              e.required
            ) ? (t(), h(le, {
              key: 0,
              additional: e.additional,
              enum: u(i.value).length > 0,
              pattern: e.pattern,
              required: e.required,
              value: i.value,
              schemas: e.schemas,
              hideModelNames: e.hideModelNames
            }, x({ _: 2 }, [
              e.name ? {
                name: "name",
                fn: f(() => [
                  B(g(e.name), 1)
                ]),
                key: "0"
              } : void 0,
              (N = i.value) != null && N.example ? {
                name: "example",
                fn: f(() => [
                  B(" Example: " + g(i.value.example), 1)
                ]),
                key: "1"
              } : void 0
            ]), 1032, ["additional", "enum", "pattern", "required", "value", "schemas", "hideModelNames"])) : l("", !0),
            P(e.description, i.value) ? (t(), r("div", pe, [
              m(p(O), {
                value: P(e.description, i.value)
              }, null, 8, ["value"])
            ])) : C(i.value) ? (t(), r("div", ce, [
              m(p(O), {
                value: C(i.value) || ""
              }, null, 8, ["value"])
            ])) : l("", !0),
            ((S = u(i.value)) == null ? void 0 : S.length) > 0 && !e.isDiscriminator ? (t(), r("div", de, [
              Q.value ? (t(), r("div", ue, [
                (t(!0), r(v, null, M(u(i.value), (a) => {
                  var c, b;
                  return t(), r("div", {
                    key: a,
                    class: "property"
                  }, [
                    k("div", ye, [
                      k("div", he, g(a), 1)
                    ]),
                    k("div", fe, [
                      m(p(O), {
                        value: (b = (c = i.value) == null ? void 0 : c["x-enumDescriptions"]) == null ? void 0 : b[a]
                      }, null, 8, ["value"])
                    ])
                  ]);
                }), 128))
              ])) : (t(), r("ul", ge, [
                (t(!0), r(v, null, M(z.value, (a) => (t(), r("li", {
                  key: a,
                  class: "property-enum-value"
                }, [
                  k("span", ve, g(a), 1)
                ]))), 128)),
                H.value ? (t(), h(p(ee), { key: 0 }, {
                  default: f(({ open: a }) => [
                    m(p(ne), null, {
                      default: f(() => [
                        (t(!0), r(v, null, M(L.value, (c) => (t(), r("li", {
                          key: c,
                          class: "property-enum-value"
                        }, [
                          k("span", be, g(c), 1)
                        ]))), 128))
                      ]),
                      _: 1
                    }),
                    m(p(ie), { class: "enum-toggle-button" }, {
                      default: f(() => [
                        m(p(te), {
                          class: R(["enum-toggle-button-icon", { "enum-toggle-button-icon--open": a }]),
                          icon: "Add",
                          size: "sm"
                        }, null, 8, ["class"]),
                        B(" " + g(a ? "Hide values" : "Show all values"), 1)
                      ]),
                      _: 2
                    }, 1024)
                  ]),
                  _: 1
                })) : l("", !0)
              ]))
            ])) : l("", !0),
            K.value ? (t(), r("div", ke, [
              m(T, {
                compact: e.compact,
                level: e.level + 1,
                name: e.name,
                noncollapsible: e.noncollapsible,
                value: s.value,
                resolvedSchema: s.value,
                discriminatorMapping: e.discriminatorMapping,
                discriminatorPropertyName: e.discriminatorPropertyName,
                schemas: e.schemas,
                "onUpdate:modelValue": j
              }, null, 8, ["compact", "level", "name", "noncollapsible", "value", "resolvedSchema", "discriminatorMapping", "discriminatorPropertyName", "schemas"])
            ])) : l("", !0),
            (A = i.value) != null && A.items && typeof i.value.items == "object" ? (t(), r(v, { key: 5 }, [
              J.value ? (t(), r("div", De, [
                m(T, {
                  compact: e.compact,
                  level: e.level + 1,
                  name: e.name,
                  noncollapsible: e.noncollapsible,
                  value: s.value && typeof s.value == "object" && "items" in s.value ? s.value.items : i.value.items,
                  resolvedSchema: s.value && typeof s.value == "object" && "items" in s.value ? s.value.items : i.value.items,
                  discriminatorMapping: e.discriminatorMapping,
                  discriminatorPropertyName: e.discriminatorPropertyName,
                  schemas: e.schemas,
                  "onUpdate:modelValue": j
                }, null, 8, ["compact", "level", "name", "noncollapsible", "value", "resolvedSchema", "discriminatorMapping", "discriminatorPropertyName", "schemas"])
              ])) : l("", !0)
            ], 64)) : l("", !0),
            (t(!0), r(v, null, M(p(re), (a) => {
              var c, b, I;
              return t(), r(v, { key: a }, [
                (c = i.value) != null && c[a] && !((b = i.value) != null && b.items && typeof a == "string" && typeof i.value.items == "object" && a in i.value.items) ? (t(), h(U, {
                  key: 0,
                  compact: e.compact,
                  composition: a,
                  hideHeading: e.hideHeading,
                  level: e.level,
                  name: e.name,
                  noncollapsible: e.noncollapsible,
                  schemas: e.schemas,
                  value: i.value
                }, null, 8, ["compact", "composition", "hideHeading", "level", "name", "noncollapsible", "schemas", "value"])) : G(a) ? (t(), h(U, {
                  key: 1,
                  compact: e.compact,
                  composition: a,
                  hideHeading: e.hideHeading,
                  level: e.level,
                  name: e.name,
                  noncollapsible: e.noncollapsible,
                  schemas: e.schemas,
                  value: (I = i.value) == null ? void 0 : I.items
                }, null, 8, ["compact", "composition", "hideHeading", "level", "name", "noncollapsible", "schemas", "value"])) : l("", !0)
              ], 64);
            }), 128)),
            e.isDiscriminator && e.discriminatorMapping && e.compact ? (t(), h(se, {
              key: 6,
              "discriminator-mapping": e.discriminatorMapping,
              discriminator: Z.value,
              "onUpdate:modelValue": j
            }, null, 8, ["discriminator-mapping", "discriminator"])) : l("", !0),
            m(p(me), { value: i.value }, null, 8, ["value"])
          ];
        }),
        _: 1
      }, 8, ["class"]);
    };
  }
});
export {
  Ve as default
};
