import { defineComponent, computed, createBlock, openBlock, resolveDynamicComponent, normalizeClass, withCtx, createCommentVNode, createElementBlock, createVNode, createSlots, unref, createTextVNode, toDisplayString, Fragment, renderList } from "vue";
import { ScalarWrappingText, ScalarMarkdown } from "@scalar/components";
import { getResolvedRef } from "@scalar/workspace-store/helpers/get-resolved-ref";
import { isArraySchema } from "@scalar/workspace-store/schemas/v3.1/strict/type-guards";
import { isTypeObject } from "./helpers/is-type-object.js";
import { getCompositionsToRender } from "./helpers/get-compositions-to-render.js";
import { getEnumValues } from "./helpers/get-enum-values.js";
import { getPropertyDescription } from "./helpers/get-property-description.js";
import { hasComplexArrayItems } from "./helpers/has-complex-array-items.js";
import { optimizeValueForDisplay } from "./helpers/optimize-value-for-display.js";
import { shouldDisplayDescription } from "./helpers/should-display-description.js";
import { shouldDisplayHeading } from "./helpers/should-display-heading.js";
import Schema from "./Schema.vue.js";
import _sfc_main$2 from "./SchemaComposition.vue.js";
import SchemaEnumValues from "./SchemaEnumValues.vue.js";
import SchemaPropertyHeading from "./SchemaPropertyHeading.vue.js";
import _sfc_main$1 from "../../Anchor/WithBreadcrumb.vue.js";
import _sfc_main$3 from "../../../features/specification-extension/SpecificationExtension.vue2.js";
const _hoisted_1 = {
  key: 0,
  class: "property-name-pattern-properties"
};
const _hoisted_2 = {
  key: 1,
  class: "property-name-additional-properties"
};
const _hoisted_3 = {
  key: 1,
  class: "property-description"
};
const _hoisted_4 = {
  key: 3,
  class: "children"
};
const _hoisted_5 = {
  key: 4,
  class: "children"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "SchemaProperty",
  props: {
    is: {},
    schema: {},
    noncollapsible: { type: Boolean },
    level: { default: 0 },
    name: {},
    required: { type: Boolean, default: false },
    compact: { type: Boolean, default: false },
    discriminator: {},
    description: {},
    hideModelNames: { type: Boolean, default: false },
    hideHeading: { type: Boolean },
    variant: {},
    breadcrumb: {},
    eventBus: {},
    options: {}
  },
  setup(__props) {
    const props = __props;
    const optimizedValue = computed(() => optimizeValueForDisplay(props.schema));
    const childBreadcrumb = computed(
      () => props.breadcrumb && props.name ? [...props.breadcrumb, props.name] : void 0
    );
    const shouldHaveLink = computed(() => props.level <= 1);
    const hasComplexArrayItemsComputed = computed(
      () => hasComplexArrayItems(optimizedValue.value)
    );
    const hasEnum = computed(() => enumValues.value.length > 0);
    const shouldRenderObjectProperties = computed(() => {
      const value = optimizedValue.value;
      if (!value) {
        return false;
      }
      return isTypeObject(value) && ("properties" in value || "additionalProperties" in value);
    });
    const shouldRenderArrayOfObjects = computed(() => {
      const value = optimizedValue.value;
      if (!value || !isArraySchema(value) || typeof value.items !== "object") {
        return false;
      }
      return hasComplexArrayItemsComputed.value;
    });
    const enumValues = computed(() => getEnumValues(optimizedValue.value));
    const propertyDescription = computed(
      () => getPropertyDescription(optimizedValue.value)
    );
    const displayDescription = computed(
      () => shouldDisplayDescription(optimizedValue.value, props.description)
    );
    const shouldDisplayHeadingComputed = computed(
      () => shouldDisplayHeading(optimizedValue.value, props.name, props.required)
    );
    const compositionsToRender = computed(
      () => getCompositionsToRender(optimizedValue.value)
    );
    const resolvedArrayItems = computed(() => {
      const value = optimizedValue.value;
      if (!value || !isArraySchema(value) || typeof value.items !== "object") {
        return void 0;
      }
      return getResolvedRef(value.items);
    });
    const isDiscriminatorProperty = computed(
      () => Boolean(props.name && props.discriminator?.propertyName === props.name)
    );
    return (_ctx, _cache) => {
      return openBlock(), createBlock(resolveDynamicComponent(__props.is ?? "li"), {
        class: normalizeClass(["property", [
          `property--level-${__props.level}`,
          {
            "property--compact": __props.compact,
            "property--deprecated": optimizedValue.value?.deprecated
          }
        ]])
      }, {
        default: withCtx(() => [
          shouldDisplayHeadingComputed.value ? (openBlock(), createBlock(SchemaPropertyHeading, {
            key: 0,
            class: "group",
            enum: hasEnum.value,
            hideModelNames: __props.hideModelNames,
            isDiscriminator: isDiscriminatorProperty.value,
            required: __props.required,
            value: optimizedValue.value
          }, createSlots({ _: 2 }, [
            __props.name ? {
              name: "name",
              fn: withCtx(() => [
                createVNode(unref(_sfc_main$1), {
                  breadcrumb: shouldHaveLink.value ? childBreadcrumb.value : void 0,
                  eventBus: __props.eventBus
                }, {
                  default: withCtx(() => [
                    __props.variant === "patternProperties" ? (openBlock(), createElementBlock("span", _hoisted_1, [
                      createVNode(unref(ScalarWrappingText), {
                        preset: "property",
                        text: __props.name
                      }, null, 8, ["text"])
                    ])) : __props.variant === "additionalProperties" ? (openBlock(), createElementBlock("span", _hoisted_2, [
                      createVNode(unref(ScalarWrappingText), {
                        preset: "property",
                        text: __props.name
                      }, null, 8, ["text"])
                    ])) : (openBlock(), createBlock(unref(ScalarWrappingText), {
                      key: 2,
                      preset: "property",
                      text: __props.name
                    }, null, 8, ["text"]))
                  ]),
                  _: 1
                }, 8, ["breadcrumb", "eventBus"])
              ]),
              key: "0"
            } : void 0,
            optimizedValue.value?.example ? {
              name: "example",
              fn: withCtx(() => [
                createTextVNode(" Example: " + toDisplayString(optimizedValue.value.example), 1)
              ]),
              key: "1"
            } : void 0
          ]), 1032, ["enum", "hideModelNames", "isDiscriminator", "required", "value"])) : createCommentVNode("", true),
          displayDescription.value || propertyDescription.value ? (openBlock(), createElementBlock("div", _hoisted_3, [
            createVNode(unref(ScalarMarkdown), {
              value: displayDescription.value || propertyDescription.value || ""
            }, null, 8, ["value"])
          ])) : createCommentVNode("", true),
          hasEnum.value ? (openBlock(), createBlock(SchemaEnumValues, {
            key: 2,
            value: optimizedValue.value
          }, null, 8, ["value"])) : createCommentVNode("", true),
          shouldRenderObjectProperties.value ? (openBlock(), createElementBlock("div", _hoisted_4, [
            createVNode(Schema, {
              breadcrumb: childBreadcrumb.value,
              compact: __props.compact,
              eventBus: __props.eventBus,
              level: __props.level + 1,
              name: __props.name,
              noncollapsible: __props.noncollapsible,
              options: __props.options,
              schema: optimizedValue.value
            }, null, 8, ["breadcrumb", "compact", "eventBus", "level", "name", "noncollapsible", "options", "schema"])
          ])) : createCommentVNode("", true),
          shouldRenderArrayOfObjects.value && resolvedArrayItems.value ? (openBlock(), createElementBlock("div", _hoisted_5, [
            createVNode(Schema, {
              compact: __props.compact,
              eventBus: __props.eventBus,
              level: __props.level + 1,
              name: __props.name,
              noncollapsible: __props.noncollapsible,
              options: __props.options,
              schema: resolvedArrayItems.value
            }, null, 8, ["compact", "eventBus", "level", "name", "noncollapsible", "options", "schema"])
          ])) : createCommentVNode("", true),
          (openBlock(true), createElementBlock(Fragment, null, renderList(compositionsToRender.value, (compositionData) => {
            return openBlock(), createBlock(_sfc_main$2, {
              key: compositionData.composition,
              breadcrumb: __props.breadcrumb,
              compact: __props.compact,
              composition: compositionData.composition,
              discriminator: __props.schema?.discriminator,
              eventBus: __props.eventBus,
              hideHeading: __props.hideHeading,
              level: __props.level,
              name: __props.name,
              noncollapsible: __props.noncollapsible,
              options: __props.options,
              schema: unref(getResolvedRef)(props.schema)
            }, null, 8, ["breadcrumb", "compact", "composition", "discriminator", "eventBus", "hideHeading", "level", "name", "noncollapsible", "options", "schema"]);
          }), 128)),
          createVNode(unref(_sfc_main$3), { value: optimizedValue.value }, null, 8, ["value"])
        ]),
        _: 1
      }, 8, ["class"]);
    };
  }
});
export {
  _sfc_main as default
};
