import { defineComponent as F, ref as M, computed as t, resolveComponent as T, createElementBlock as c, openBlock as r, createCommentVNode as u, createBlock as p, Fragment as N, renderList as j, createVNode as y, createElementVNode as f, unref as d, withCtx as R, toDisplayString as V } from "vue";
import { ScalarListbox as Z, ScalarMarkdown as $ } from "@scalar/components";
import { ScalarIconCaretDown as G } from "@scalar/icons";
import { mergeAllOfSchemas as w } from "./helpers/merge-all-of-schemas.js";
import { getModelNameFromSchema as J } from "./helpers/schema-name.js";
import { hasComposition as b } from "./helpers/schema-composition.js";
import g from "./Schema.vue.js";
const K = { class: "property-rule" }, P = {
  class: "composition-selector bg-b-1.5 hover:bg-b-2 flex w-full cursor-pointer items-center gap-1 rounded-t-lg border border-b-0 px-2 py-1.25 pr-3 text-left",
  type: "button"
}, Q = { class: "text-c-2" }, X = { class: "composition-selector-label text-c-1" }, Y = { class: "composition-panel" }, W = {
  key: 0,
  class: "property-description border-x border-t p-2"
}, te = /* @__PURE__ */ F({
  __name: "SchemaComposition",
  props: {
    composition: {},
    schemas: {},
    name: {},
    value: {},
    level: {},
    compact: { type: Boolean },
    hideHeading: { type: Boolean }
  },
  setup(s) {
    const v = M(0), B = t(() => k.value), C = t(
      () => B.value.map(
        (e, o) => ({
          id: String(o),
          label: J(e) || "Schema"
        })
      )
    ), O = t({
      get: () => C.value.find(
        (e) => e.id === String(v.value)
      ),
      set: (e) => v.value = Number(e.id)
    }), D = t(() => {
      var i;
      const e = ["oneOf", "anyOf"].includes(s.composition), o = s.composition === "allOf" && ((i = s.value[s.composition]) == null ? void 0 : i.some((l) => b(l)));
      return e || o;
    }), I = (e) => e.find((o) => b(o)), L = (e) => !e.allOf || !Array.isArray(e.allOf) ? !1 : e.allOf.some(
      (o) => o.oneOf || o.anyOf || o.allOf
    ), S = (e) => e.allOf && Array.isArray(e.allOf) ? L(e) ? e : w(e.allOf) : e, k = t(() => {
      const e = s.value[s.composition], o = I(e);
      return !o || s.composition !== "allOf" && o.allOf ? e.map(S) : (o.oneOf || o.anyOf || o.allOf).map(S);
    }), U = (e) => {
      var o, i;
      if (e === "allOf") {
        const l = (i = (o = s.value) == null ? void 0 : o[e]) == null ? void 0 : i.find(
          (m) => b(m)
        );
        if (l != null && l.oneOf)
          return "One of";
        if (l != null && l.anyOf)
          return "Any of";
      }
      return e.replace(/([A-Z])/g, " $1").replace(/^./, (l) => l.toUpperCase()).toLowerCase().replace(/^(\w)/, (l) => l.toUpperCase());
    }, a = t(
      () => k.value[v.value]
    ), h = t(() => {
      var e;
      return (e = a.value) != null && e.oneOf ? "oneOf" : "anyOf";
    }), q = t(() => {
      var o;
      const e = h.value;
      return (o = a.value) == null ? void 0 : o[e];
    }), z = t(() => {
      const e = a.value;
      return e ? !!(e.properties || e.type || e.nullable || e.const !== void 0 || e.enum || e.allOf || e.oneOf || e.anyOf || e.items) : !1;
    });
    return (e, o) => {
      var l, m, A, H;
      const i = T("SchemaComposition", !0);
      return r(), c("div", K, [
        e.composition === "allOf" && e.value[e.composition].some((n) => n.oneOf || n.anyOf) ? (r(!0), c(N, { key: 0 }, j(e.value[e.composition].filter(
          (n) => !n.oneOf && !n.anyOf
        ), (n, E) => (r(), p(g, {
          key: E,
          compact: e.compact,
          level: e.level,
          name: e.name,
          noncollapsible: e.level == 0,
          schemas: e.schemas,
          value: n
        }, null, 8, ["compact", "level", "name", "noncollapsible", "schemas", "value"]))), 128)) : u("", !0),
        D.value ? (r(), c(N, { key: 1 }, [
          y(d(Z), {
            modelValue: O.value,
            "onUpdate:modelValue": o[0] || (o[0] = (n) => O.value = n),
            options: C.value,
            resize: ""
          }, {
            default: R(() => {
              var n;
              return [
                f("button", P, [
                  f("span", Q, V(U(e.composition)), 1),
                  f("span", X, V(((n = O.value) == null ? void 0 : n.label) || "Schema"), 1),
                  y(d(G))
                ])
              ];
            }),
            _: 1
          }, 8, ["modelValue", "options"]),
          f("div", Y, [
            (l = a.value) != null && l.description ? (r(), c("div", W, [
              y(d($), {
                value: a.value.description
              }, null, 8, ["value"])
            ])) : u("", !0),
            z.value ? (r(), p(g, {
              key: 1,
              compact: e.compact,
              level: e.level + 1,
              hideHeading: e.hideHeading,
              name: e.name,
              noncollapsible: !0,
              schemas: e.schemas,
              value: (m = a.value) != null && m.properties ? {
                type: "object",
                properties: a.value.properties,
                required: a.value.required
              } : a.value
            }, null, 8, ["compact", "level", "hideHeading", "name", "schemas", "value"])) : u("", !0),
            (A = a.value) != null && A.oneOf || (H = a.value) != null && H.anyOf ? (r(), p(i, {
              key: 2,
              compact: e.compact,
              composition: h.value,
              hideHeading: e.hideHeading,
              level: e.level + 1,
              name: e.name,
              noncollapsible: !0,
              schemas: e.schemas,
              value: {
                [h.value]: q.value
              }
            }, null, 8, ["compact", "composition", "hideHeading", "level", "name", "schemas", "value"])) : u("", !0)
          ])
        ], 64)) : (r(), p(g, {
          key: 2,
          compact: e.compact,
          level: e.level,
          name: e.name,
          noncollapsible: e.level == 0,
          schemas: e.schemas,
          value: d(w)(e.value[e.composition])
        }, null, 8, ["compact", "level", "name", "noncollapsible", "schemas", "value"]))
      ]);
    };
  }
});
export {
  te as default
};
