import { defineComponent as B, ref as v, onMounted as N, nextTick as L, computed as C, createElementBlock as b, openBlock as n, createBlock as i, unref as l, withCtx as o, createVNode as u, createElementVNode as m, toDisplayString as y, Fragment as V, renderList as O, normalizeClass as T } from "vue";
import { TabGroup as U, TabList as A, Tab as D, TabPanel as H } from "@headlessui/vue";
import { cva as $, cx as w, ScalarListbox as E } from "@scalar/components";
import { ScalarIconCaretDown as F } from "@scalar/icons";
import { stringify as z } from "flatted";
import { mergeAllOfSchemas as I } from "./helpers/merge-all-of-schemas.js";
import h from "./Schema.vue.js";
const M = { class: "property-rule" }, W = { class: "text-c-3" }, G = { class: "schema-tab-label z-1 relative" }, P = { class: "schema-tab-label z-1 text-c-1 relative" }, x = /* @__PURE__ */ B({
  __name: "SchemaDiscriminator",
  props: {
    discriminator: {},
    schemas: {},
    name: {},
    value: {},
    level: {},
    compact: { type: Boolean },
    hideHeading: { type: Boolean }
  },
  setup(s) {
    const r = v(0), d = v(null), p = v(!1);
    N(async () => {
      if (await L(), d.value) {
        const e = d.value;
        p.value = e.scrollWidth > e.clientWidth;
      }
    });
    const g = $({
      base: "schema-tab",
      variants: {
        selected: {
          true: "schema-tab-selected",
          false: "text-c-3"
        }
      }
    }), k = C(
      () => s.value[s.discriminator].map((e, a) => ({
        id: String(a),
        label: S(e) || "Schema"
      }))
    ), f = C({
      get: () => k.value.find(
        (e) => e.id === String(r.value)
      ),
      set: (e) => r.value = Number(e.id)
    }), S = (e) => {
      if (!e)
        return null;
      if (e.name)
        return e.name;
      if (e.title)
        return e.title;
      if (s.schemas && typeof s.schemas == "object") {
        for (const [a, t] of Object.entries(s.schemas))
          if (z(t) === z(e))
            return a;
        return Object.keys(e)[0];
      }
      if (e.type === "array" && e.items)
        return `Array of ${e.items.type || "any"}`;
      if (e.type)
        return e.type;
      if (typeof e == "object") {
        const a = Object.keys(e);
        if (a.length > 0)
          return a[0];
      }
      return null;
    }, j = (e) => e.replace(/([A-Z])/g, " $1").replace(/^./, (a) => a.toUpperCase()).toLowerCase().replace(/^(\w)/, (a) => a.toUpperCase());
    return (e, a) => (n(), b("div", M, [
      e.discriminator === "oneOf" || e.discriminator === "anyOf" ? (n(), i(l(U), {
        key: 0,
        modelValue: r.value,
        "onUpdate:modelValue": a[1] || (a[1] = (t) => r.value = t),
        as: "div"
      }, {
        default: o(() => [
          u(l(A), { class: "discriminator-tab-list py-1.25 flex flex-col gap-1 rounded-t-lg border border-b-0 px-2 pr-3" }, {
            default: o(() => [
              m("span", W, y(j(e.discriminator)), 1),
              m("div", {
                ref_key: "tabsContainer",
                ref: d,
                class: "flex items-center gap-1.5"
              }, [
                p.value ? (n(), i(l(E), {
                  key: 1,
                  modelValue: f.value,
                  "onUpdate:modelValue": a[0] || (a[0] = (t) => f.value = t),
                  options: k.value,
                  resize: ""
                }, {
                  default: o(() => {
                    var t;
                    return [
                      m("div", {
                        class: T(["flex cursor-pointer items-center gap-1", l(w)(l(g)({ selected: !0 }))])
                      }, [
                        m("span", P, y(((t = f.value) == null ? void 0 : t.label) || "Schema"), 1),
                        u(l(F), { class: "z-1" })
                      ], 2)
                    ];
                  }),
                  _: 1
                }, 8, ["modelValue", "options"])) : (n(!0), b(V, { key: 0 }, O(e.value[e.discriminator], (t, c) => (n(), i(l(D), {
                  key: c,
                  class: T(
                    l(w)(l(g)({ selected: r.value === c }))
                  ),
                  onClick: (Z) => r.value = c
                }, {
                  default: o(() => [
                    m("span", G, y(S(t) || "Schema"), 1)
                  ]),
                  _: 2
                }, 1032, ["class", "onClick"]))), 128))
              ], 512)
            ]),
            _: 1
          }),
          p.value ? (n(), i(l(H), {
            key: 1,
            class: "discriminator-panel"
          }, {
            default: o(() => [
              u(h, {
                compact: e.compact,
                hideHeading: e.hideHeading,
                name: e.name,
                noncollapsible: !0,
                schemas: e.schemas,
                value: e.value[e.discriminator][r.value]
              }, null, 8, ["compact", "hideHeading", "name", "schemas", "value"])
            ]),
            _: 1
          })) : (n(!0), b(V, { key: 0 }, O(e.value[e.discriminator], (t, c) => (n(), i(l(H), {
            key: c,
            class: "discriminator-panel"
          }, {
            default: o(() => [
              u(h, {
                compact: e.compact,
                hideHeading: e.hideHeading,
                name: e.name,
                noncollapsible: !0,
                schemas: e.schemas,
                value: t
              }, null, 8, ["compact", "hideHeading", "name", "schemas", "value"])
            ]),
            _: 2
          }, 1024))), 128))
        ]),
        _: 1
      }, 8, ["modelValue"])) : (n(), i(h, {
        key: 1,
        compact: e.compact,
        level: e.level,
        name: e.name,
        noncollapsible: e.level == 0,
        schemas: e.schemas,
        value: l(I)(e.value[e.discriminator])
      }, null, 8, ["compact", "level", "name", "noncollapsible", "schemas", "value"]))
    ]));
  }
});
export {
  x as default
};
