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