import { defineComponent as j, computed as f, ref as C, createElementBlock as a, createCommentVNode as i, openBlock as l, createElementVNode as b, createVNode as n, renderSlot as E, unref as d } from "vue";
import { ScalarMarkdown as P } from "@scalar/components";
import S from "./ContentTypeSelect.vue.js";
import y from "../../../components/Content/Schema/Schema.vue.js";
const _ = { key: 0 }, O = { class: "request-body-header" }, R = { class: "request-body-title" }, g = {
  key: 0,
  class: "request-body-required"
}, N = {
  key: 0,
  class: "request-body-description"
}, T = {
  key: 0,
  class: "request-body-schema"
}, M = {
  key: 1,
  class: "request-body-schema"
}, z = /* @__PURE__ */ j({
  __name: "RequestBody",
  props: {
    requestBody: {},
    schemas: {}
  },
  emits: ["update:modelValue"],
  setup(c, { emit: k }) {
    var q;
    const V = k, v = f(
      () => {
        var e;
        return Object.keys(((e = c.requestBody) == null ? void 0 : e.content) ?? {});
      }
    ), t = C("application/json");
    (q = c.requestBody) != null && q.content && v.value.length > 0 && (t.value = v.value[0]);
    const m = f(() => {
      var r, u, B;
      const e = (B = (u = (r = c.requestBody) == null ? void 0 : r.content) == null ? void 0 : u[t.value]) == null ? void 0 : B.schema;
      if ((e == null ? void 0 : e.type) !== "object" || !e.properties)
        return null;
      const s = Object.entries(e.properties);
      if (s.length < 13)
        return null;
      const { properties: p, ...o } = e;
      return {
        visibleProperties: {
          ...o,
          properties: Object.fromEntries(s.slice(0, 12))
        },
        collapsedProperties: {
          ...o,
          properties: Object.fromEntries(s.slice(12))
        }
      };
    }), h = (e) => {
      V("update:modelValue", e);
    };
    return (e, s) => {
      var p, o, r;
      return e.requestBody ? (l(), a("div", _, [
        b("div", O, [
          b("span", R, [
            E(e.$slots, "title", {}, void 0, !0),
            e.requestBody.required ? (l(), a("div", g, " required ")) : i("", !0)
          ]),
          n(S, {
            defaultValue: t.value,
            requestBody: e.requestBody,
            onSelectContentType: s[0] || (s[0] = ({ contentType: u }) => t.value = u)
          }, null, 8, ["defaultValue", "requestBody"]),
          e.requestBody.description ? (l(), a("div", N, [
            n(d(P), {
              value: e.requestBody.description
            }, null, 8, ["value"])
          ])) : i("", !0)
        ]),
        m.value ? (l(), a("div", T, [
          n(d(y), {
            compact: "",
            name: "Request Body",
            noncollapsible: "",
            schemas: e.schemas,
            value: m.value.visibleProperties,
            "onUpdate:modelValue": h
          }, null, 8, ["schemas", "value"]),
          n(d(y), {
            additionalProperties: "",
            compact: "",
            name: "Request Body",
            schemas: e.schemas,
            value: m.value.collapsedProperties
          }, null, 8, ["schemas", "value"])
        ])) : (p = e.requestBody.content) != null && p[t.value] ? (l(), a("div", M, [
          n(d(y), {
            compact: "",
            name: "Request Body",
            noncollapsible: "",
            schemas: e.schemas,
            value: (r = (o = e.requestBody.content) == null ? void 0 : o[t.value]) == null ? void 0 : r.schema,
            "onUpdate:modelValue": h
          }, null, 8, ["schemas", "value"])
        ])) : i("", !0)
      ])) : i("", !0);
    };
  }
});
export {
  z as default
};
