import { defineComponent, computed, createBlock, createCommentVNode, openBlock, unref, withCtx, createElementVNode, normalizeClass, createElementBlock, createVNode, withDirectives, createTextVNode, toDisplayString, vShow, normalizeStyle, Fragment } from "vue";
import { Disclosure, DisclosureButton, DisclosurePanel } from "@headlessui/vue";
import { ScalarMarkdown, ScalarIcon } from "@scalar/components";
import ScreenReader from "../../ScreenReader.vue.js";
import { isEmptySchemaObject } from "./helpers/is-empty-schema-object.js";
import { isTypeObject } from "./helpers/is-type-object.js";
import SchemaHeading from "./SchemaHeading.vue.js";
import _sfc_main$1 from "./SchemaObjectProperties.vue.js";
import SchemaProperty from "./SchemaProperty.vue.js";
const _hoisted_1 = {
  key: 0,
  class: "schema-card-description"
};
const _hoisted_2 = {
  key: 1,
  class: "pt-2"
};
const _hoisted_3 = {
  key: 0,
  class: "schema-properties"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "Schema",
  props: {
    schema: {},
    level: { default: 0 },
    name: {},
    compact: { type: Boolean },
    noncollapsible: { type: Boolean, default: false },
    hideHeading: { type: Boolean },
    additionalProperties: { type: Boolean },
    hideModelNames: { type: Boolean, default: false },
    discriminator: {},
    breadcrumb: {},
    eventBus: {},
    options: {}
  },
  setup(__props) {
    const shouldShowToggle = computed(() => {
      return !__props.noncollapsible && __props.level > 0;
    });
    const schemaDescription = computed(() => {
      if (__props.schema?.allOf && __props.schema.allOf.length > 0 && __props.name === "Request Body") {
        return __props.schema.description || __props.schema.allOf[0]?.description || null;
      }
      if (!__props.schema?.description || typeof __props.schema.description !== "string") {
        return null;
      }
      if (__props.schema.oneOf || __props.schema.anyOf) {
        return null;
      }
      if (__props.schema.enum) {
        return null;
      }
      if (!("properties" in __props.schema) && !("patternProperties" in __props.schema) && !("additionalProperties" in __props.schema)) {
        return null;
      }
      return __props.schema.description;
    });
    const handleClick = (e) => __props.noncollapsible && e.stopPropagation();
    return (_ctx, _cache) => {
      return typeof _ctx.schema === "object" && Object.keys(_ctx.schema).length ? (openBlock(), createBlock(unref(Disclosure), {
        key: 0,
        defaultOpen: _ctx.noncollapsible
      }, {
        default: withCtx(({ open }) => [
          createElementVNode("div", {
            class: normalizeClass(["schema-card", [
              `schema-card--level-${_ctx.level}`,
              { "schema-card--compact": _ctx.compact, "schema-card--open": open },
              { "border-t": _ctx.additionalProperties && open }
            ]])
          }, [
            schemaDescription.value ? (openBlock(), createElementBlock("div", _hoisted_1, [
              createVNode(unref(ScalarMarkdown), { value: schemaDescription.value }, null, 8, ["value"])
            ])) : createCommentVNode("", true),
            unref(isEmptySchemaObject)(_ctx.schema) ? (openBlock(), createElementBlock("div", _hoisted_2, " Empty object ")) : createCommentVNode("", true),
            createElementVNode("div", {
              class: normalizeClass(["schema-properties", {
                "schema-properties-open": open
              }])
            }, [
              _ctx.additionalProperties ? withDirectives((openBlock(), createElementBlock("div", _hoisted_3, [
                createVNode(unref(DisclosureButton), {
                  as: "button",
                  class: "schema-card-title schema-card-title--compact",
                  onClickCapture: handleClick
                }, {
                  default: withCtx(() => [
                    createVNode(unref(ScalarIcon), {
                      class: "schema-card-title-icon",
                      icon: "Add",
                      size: "sm"
                    }),
                    _cache[0] || (_cache[0] = createTextVNode(" Show additional properties ", -1)),
                    _ctx.name ? (openBlock(), createBlock(ScreenReader, { key: 0 }, {
                      default: withCtx(() => [
                        createTextVNode("for " + toDisplayString(_ctx.name), 1)
                      ]),
                      _: 1
                    })) : createCommentVNode("", true)
                  ]),
                  _: 1
                })
              ], 512)), [
                [vShow, !open]
              ]) : shouldShowToggle.value ? withDirectives((openBlock(), createBlock(unref(DisclosureButton), {
                key: 1,
                as: _ctx.noncollapsible ? "div" : "button",
                class: normalizeClass(["schema-card-title", { "schema-card-title--compact": _ctx.compact }]),
                style: normalizeStyle({
                  top: `calc(var(--refs-viewport-offset) +  calc(var(--schema-title-height) * ${_ctx.level}))`
                }),
                onClickCapture: handleClick
              }, {
                default: withCtx(() => [
                  _ctx.compact ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
                    createVNode(unref(ScalarIcon), {
                      class: normalizeClass(["schema-card-title-icon", { "schema-card-title-icon--open": open }]),
                      icon: "Add",
                      size: "sm"
                    }, null, 8, ["class"]),
                    open ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
                      createTextVNode(" Hide " + toDisplayString(_ctx.schema?.title ?? "Child Attributes"), 1)
                    ], 64)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
                      createTextVNode(" Show " + toDisplayString(_ctx.schema?.title ?? "Child Attributes"), 1)
                    ], 64)),
                    _ctx.name ? (openBlock(), createBlock(ScreenReader, { key: 2 }, {
                      default: withCtx(() => [
                        createTextVNode("for " + toDisplayString(_ctx.name), 1)
                      ]),
                      _: 1
                    })) : createCommentVNode("", true)
                  ], 64)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
                    createVNode(unref(ScalarIcon), {
                      class: normalizeClass(["schema-card-title-icon", { "schema-card-title-icon--open": open }]),
                      icon: "Add",
                      size: "sm"
                    }, null, 8, ["class"]),
                    createVNode(SchemaHeading, {
                      name: _ctx.schema?.title ?? _ctx.name,
                      value: _ctx.schema
                    }, null, 8, ["name", "value"])
                  ], 64))
                ]),
                _: 2
              }, 1032, ["as", "class", "style"])), [
                [vShow, !_ctx.hideHeading && !(_ctx.noncollapsible && _ctx.compact)]
              ]) : createCommentVNode("", true),
              !_ctx.additionalProperties || open ? (openBlock(), createBlock(unref(DisclosurePanel), {
                key: 2,
                as: "ul",
                static: !shouldShowToggle.value
              }, {
                default: withCtx(() => [
                  unref(isTypeObject)(_ctx.schema) ? (openBlock(), createBlock(_sfc_main$1, {
                    key: 0,
                    breadcrumb: _ctx.breadcrumb,
                    compact: _ctx.compact,
                    discriminator: _ctx.discriminator,
                    eventBus: _ctx.eventBus,
                    hideHeading: _ctx.hideHeading,
                    hideModelNames: _ctx.hideModelNames,
                    level: _ctx.level + 1,
                    options: _ctx.options,
                    schema: _ctx.schema
                  }, null, 8, ["breadcrumb", "compact", "discriminator", "eventBus", "hideHeading", "hideModelNames", "level", "options", "schema"])) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
                    _ctx.schema ? (openBlock(), createBlock(SchemaProperty, {
                      key: 0,
                      breadcrumb: _ctx.breadcrumb,
                      compact: _ctx.compact,
                      eventBus: _ctx.eventBus,
                      hideHeading: _ctx.hideHeading,
                      hideModelNames: _ctx.hideModelNames,
                      level: _ctx.level,
                      options: _ctx.options,
                      schema: _ctx.schema
                    }, null, 8, ["breadcrumb", "compact", "eventBus", "hideHeading", "hideModelNames", "level", "options", "schema"])) : createCommentVNode("", true)
                  ], 64))
                ]),
                _: 1
              }, 8, ["static"])) : createCommentVNode("", true)
            ], 2)
          ], 2)
        ]),
        _: 1
      }, 8, ["defaultOpen"])) : createCommentVNode("", true);
    };
  }
});
export {
  _sfc_main as default
};
