import { defineComponent, computed, ref, createElementBlock, openBlock, createVNode, unref, withCtx, createBlock, createCommentVNode, normalizeClass, createElementVNode } from "vue";
import { Disclosure, DisclosureButton, DisclosurePanel } from "@headlessui/vue";
import { ScalarWrappingText, ScalarMarkdownSummary, ScalarMarkdown } from "@scalar/components";
import { isDefined } from "@scalar/helpers/array/is-defined";
import { ScalarIconCaretRight } from "@scalar/icons";
import { getResolvedRef } from "@scalar/workspace-store/helpers/get-resolved-ref";
import SchemaProperty from "../../../components/Content/Schema/SchemaProperty.vue.js";
import _sfc_main$1 from "./ContentTypeSelect.vue.js";
import Headers from "./Headers.vue.js";
const _hoisted_1 = { class: "parameter-item group/parameter-item" };
const _hoisted_2 = { class: "parameter-item-name min-w-0" };
const _hoisted_3 = {
  key: 1,
  class: "flex-1"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "ParameterListItem",
  props: {
    parameter: {},
    name: {},
    breadcrumb: {},
    eventBus: {},
    options: {}
  },
  setup(__props) {
    const schema = computed(
      () => "schema" in __props.parameter && __props.parameter.schema ? getResolvedRef(__props.parameter.schema) : null
    );
    const content = computed(
      () => "content" in __props.parameter && __props.parameter.content ? __props.parameter.content : null
    );
    const selectedContentType = ref(
      Object.keys(content.value || {})[0] ?? ""
    );
    const headers = computed(
      () => "headers" in __props.parameter && __props.parameter.headers ? __props.parameter.headers : null
    );
    const value = computed(() => {
      const baseSchema = content.value ? content.value?.[selectedContentType.value]?.schema : schema.value;
      const deprecated = "deprecated" in __props.parameter ? __props.parameter.deprecated : schema.value?.deprecated;
      const paramExamples = "examples" in __props.parameter ? __props.parameter.examples : {};
      const arrayExamples = schema.value?.examples ?? [];
      const recordExamples = Object.values({
        ...paramExamples,
        ...content.value?.[selectedContentType.value]?.examples
      });
      const examples = [...recordExamples, ...arrayExamples];
      return {
        ...getResolvedRef(baseSchema),
        deprecated,
        ..."example" in __props.parameter && isDefined(__props.parameter.example) && { example: __props.parameter.example },
        examples
      };
    });
    const shouldCollapse = computed(
      () => Boolean(
        __props.options.collapsableItems && (content.value || headers.value || schema.value)
      )
    );
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("li", _hoisted_1, [
        createVNode(unref(Disclosure), null, {
          default: withCtx(({ open }) => [
            shouldCollapse.value ? (openBlock(), createBlock(unref(DisclosureButton), {
              key: 0,
              class: normalizeClass(["parameter-item-trigger", { "parameter-item-trigger-open": open }])
            }, {
              default: withCtx(() => [
                createElementVNode("div", _hoisted_2, [
                  createVNode(unref(ScalarIconCaretRight), {
                    class: normalizeClass(["parameter-item-icon size-3 transition-transform duration-100", { "rotate-90": open }]),
                    weight: "bold"
                  }, null, 8, ["class"]),
                  createElementVNode("div", null, [
                    createVNode(unref(ScalarWrappingText), {
                      text: _ctx.name,
                      preset: "property"
                    }, null, 8, ["text"])
                  ])
                ]),
                !open && _ctx.parameter.description ? (openBlock(), createBlock(unref(ScalarMarkdownSummary), {
                  key: 0,
                  class: "parameter-item-description-summary min-w-0 flex-1",
                  controlled: "",
                  value: _ctx.parameter.description
                }, null, 8, ["value"])) : (openBlock(), createElementBlock("div", _hoisted_3)),
                createElementVNode("div", {
                  class: normalizeClass({
                    "w-0 overflow-hidden group-focus-within/parameter-item:w-auto group-hover/parameter-item:w-auto": !open
                  })
                }, [
                  shouldCollapse.value && content.value ? (openBlock(), createBlock(_sfc_main$1, {
                    key: 0,
                    modelValue: selectedContentType.value,
                    "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => selectedContentType.value = $event),
                    class: "",
                    content: content.value
                  }, null, 8, ["modelValue", "content"])) : createCommentVNode("", true)
                ], 2)
              ]),
              _: 2
            }, 1032, ["class"])) : createCommentVNode("", true),
            createVNode(unref(DisclosurePanel), {
              class: "parameter-item-container parameter-item-container-markdown",
              static: !shouldCollapse.value
            }, {
              default: withCtx(() => [
                shouldCollapse.value && _ctx.parameter.description ? (openBlock(), createBlock(unref(ScalarMarkdown), {
                  key: 0,
                  class: "parameter-item-description",
                  value: _ctx.parameter.description
                }, null, 8, ["value"])) : createCommentVNode("", true),
                headers.value ? (openBlock(), createBlock(Headers, {
                  key: 1,
                  breadcrumb: _ctx.breadcrumb,
                  eventBus: _ctx.eventBus,
                  headers: headers.value,
                  orderRequiredPropertiesFirst: _ctx.options.orderRequiredPropertiesFirst,
                  orderSchemaPropertiesBy: _ctx.options.orderSchemaPropertiesBy
                }, null, 8, ["breadcrumb", "eventBus", "headers", "orderRequiredPropertiesFirst", "orderSchemaPropertiesBy"])) : createCommentVNode("", true),
                createVNode(SchemaProperty, {
                  is: "div",
                  breadcrumb: _ctx.breadcrumb,
                  compact: "",
                  description: shouldCollapse.value ? "" : _ctx.parameter.description,
                  eventBus: _ctx.eventBus,
                  hideWriteOnly: true,
                  name: shouldCollapse.value ? "" : _ctx.name,
                  noncollapsible: true,
                  options: {
                    hideWriteOnly: true,
                    orderRequiredPropertiesFirst: _ctx.options.orderRequiredPropertiesFirst,
                    orderSchemaPropertiesBy: _ctx.options.orderSchemaPropertiesBy
                  },
                  required: "required" in _ctx.parameter && _ctx.parameter.required,
                  schema: value.value,
                  withExamples: typeof _ctx.options.withExamples === "boolean" ? _ctx.options.withExamples : true
                }, null, 8, ["breadcrumb", "description", "eventBus", "name", "options", "required", "schema", "withExamples"])
              ]),
              _: 1
            }, 8, ["static"])
          ]),
          _: 1
        })
      ]);
    };
  }
});
export {
  _sfc_main as default
};
