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