import { usePluginManager } from "../../../plugins/hooks/usePluginManager.js";
import SectionFilter_default from "../../../components/SectionFilter.vue.js";
import ViewLayoutSection_default from "../../../components/ViewLayout/ViewLayoutSection.vue.js";
import ResponseBody_default from "./ResponseBody.vue.js";
import RequestHeaders_default from "./RequestHeaders.vue.js";
import ResponseBodyStreaming_default from "./ResponseBodyStreaming.vue.js";
import ResponseBodyVirtual_default from "./ResponseBodyVirtual.vue.js";
import ResponseCookies_default from "./ResponseCookies.vue.js";
import ResponseEmpty_default from "./ResponseEmpty.vue.js";
import ResponseHeaders_default from "./ResponseHeaders.vue.js";
import ResponseLoadingOverlay_default from "./ResponseLoadingOverlay.vue.js";
import ResponseMetaInformation_default from "./ResponseMetaInformation.vue.js";
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, mergeProps, normalizeClass, openBlock, ref, renderList, resolveDynamicComponent, unref, useId, vShow, withCtx, withDirectives } from "vue";
import { ScalarErrorBoundary } from "@scalar/components";
//#region src/views/Request/ResponseSection/ResponseSection.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1 = { class: "flex h-8 flex-1 items-center" };
var _hoisted_2 = ["id", "role"];
var VIRTUALIZATION_THRESHOLD = 2e5;
var ResponseSection_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
	__name: "ResponseSection",
	props: {
		collection: {},
		operation: {},
		workspace: {},
		numWorkspaceRequests: {},
		response: {},
		requestResult: {}
	},
	setup(__props) {
		const responseSectionViews = usePluginManager().getViewComponents("response.section");
		const responseHeaders = computed(() => {
			const headers = __props.response?.headers;
			return headers ? Object.keys(headers).map((key) => ({
				name: key,
				value: headers[key] ?? "",
				required: false
			})) : [];
		});
		const responseCookies = computed(() => __props.response?.cookieHeaderKeys.flatMap((key) => {
			const value = __props.response?.headers?.[key];
			return value ? {
				name: key,
				value,
				required: false
			} : [];
		}) ?? []);
		const responseSections = [
			"Cookies",
			"Headers",
			"Body"
		];
		const activeFilter = ref("All");
		const filters = computed(() => ["All", ...responseSections]);
		const filterIds = computed(() => Object.fromEntries(filters.value.map((section) => [section, useId()])));
		/** Threshold for virtualizing response bodies in bytes */
		const shouldVirtualize = computed(() => {
			if (!__props.response || !("size" in __props.response)) return false;
			const contentType = __props.response.headers?.["content-type"] || __props.response.headers?.["Content-Type"];
			if (!contentType || (__props.response.size ?? 0) <= VIRTUALIZATION_THRESHOLD) return false;
			if (contentType.includes("text/html")) return false;
			return [
				"text/",
				"application/json",
				"application/ld+json",
				"application/problem+json",
				"application/vnd.api+json",
				"application/xml",
				"application/atom+xml",
				"application/rss+xml",
				"application/problem+xml",
				"application/javascript",
				"application/ecmascript",
				"application/x-yaml",
				"application/yaml",
				"application/x-httpd-php",
				"application/x-sh",
				"application/x-perl",
				"application/x-python",
				"application/x-ruby",
				"application/x-java-source",
				"application/x-www-form-urlencoded"
			].some((type) => contentType.includes(type)) && (__props.response.size ?? 0) > VIRTUALIZATION_THRESHOLD;
		});
		const requestHeaders = computed(() => __props.requestResult?.request.parameters.headers.filter((h) => h.enabled).map((h) => ({
			name: h.key,
			value: h.value,
			required: true
		})) ?? []);
		return (_ctx, _cache) => {
			return openBlock(), createBlock(ViewLayoutSection_default, { "aria-label": "Response" }, {
				title: withCtx(() => [createElementVNode("div", _hoisted_1, [createElementVNode("div", {
					"aria-live": "polite",
					class: normalizeClass(["flex items-center", { "animate-response-heading": __props.response }])
				}, [_cache[1] || (_cache[1] = createElementVNode("span", { class: "response-heading pointer-events-none absolute" }, " Response ", -1)), __props.response ? (openBlock(), createBlock(ResponseMetaInformation_default, {
					key: 0,
					class: "animate-response-children",
					response: __props.response
				}, null, 8, ["response"])) : createCommentVNode("", true)], 2), createVNode(SectionFilter_default, {
					modelValue: activeFilter.value,
					"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => activeFilter.value = $event),
					filterIds: filterIds.value,
					filters: filters.value
				}, null, 8, [
					"modelValue",
					"filterIds",
					"filters"
				])])]),
				default: withCtx(() => [createElementVNode("div", {
					id: filterIds.value.All,
					class: normalizeClass(["custom-scroll response-section-content relative grid h-full justify-stretch", { "content-start": __props.response }]),
					role: activeFilter.value === "All" && __props.response ? "tabpanel" : "none"
				}, [!__props.response ? (openBlock(), createBlock(ResponseEmpty_default, {
					key: 0,
					collection: __props.collection,
					operation: __props.operation,
					workspace: __props.workspace,
					numWorkspaceRequests: __props.numWorkspaceRequests
				}, null, 8, [
					"collection",
					"operation",
					"workspace",
					"numWorkspaceRequests"
				])) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
					activeFilter.value === "All" || activeFilter.value === "Cookies" ? (openBlock(), createBlock(ResponseCookies_default, {
						key: 0,
						class: "response-section-content-cookies",
						id: filterIds.value.Cookies,
						cookies: responseCookies.value,
						role: activeFilter.value === "All" ? "none" : "tabpanel"
					}, null, 8, [
						"id",
						"cookies",
						"role"
					])) : createCommentVNode("", true),
					activeFilter.value === "All" || activeFilter.value === "Headers" ? (openBlock(), createBlock(RequestHeaders_default, {
						key: 1,
						class: "response-section-content-headers",
						id: filterIds.value.Headers,
						headers: requestHeaders.value,
						role: activeFilter.value === "All" ? "none" : "tabpanel"
					}, null, 8, [
						"id",
						"headers",
						"role"
					])) : createCommentVNode("", true),
					activeFilter.value === "All" || activeFilter.value === "Headers" ? (openBlock(), createBlock(ResponseHeaders_default, {
						key: 2,
						class: "response-section-content-headers",
						id: filterIds.value.Headers,
						headers: responseHeaders.value,
						role: activeFilter.value === "All" ? "none" : "tabpanel"
					}, null, 8, [
						"id",
						"headers",
						"role"
					])) : createCommentVNode("", true),
					(openBlock(true), createElementBlock(Fragment, null, renderList(unref(responseSectionViews), (view, index) => {
						return openBlock(), createBlock(unref(ScalarErrorBoundary), { key: view.title ?? index }, {
							default: withCtx(() => [withDirectives((openBlock(), createBlock(resolveDynamicComponent(view.component), mergeProps({ ref_for: true }, view.props ?? {}), null, 16)), [[vShow, activeFilter.value === "All" || activeFilter.value === view.title]])]),
							_: 2
						}, 1024);
					}), 128)),
					activeFilter.value === "All" || activeFilter.value === "Body" ? (openBlock(), createElementBlock(Fragment, { key: 3 }, ["reader" in __props.response ? (openBlock(), createBlock(ResponseBodyStreaming_default, {
						key: 0,
						class: "response-section-content-body",
						id: filterIds.value.Body,
						reader: __props.response.reader
					}, null, 8, ["id", "reader"])) : shouldVirtualize.value && typeof __props.response?.data === "string" ? (openBlock(), createBlock(ResponseBodyVirtual_default, {
						key: 1,
						id: filterIds.value.Body,
						content: __props.response.data,
						data: __props.response?.data,
						headers: responseHeaders.value,
						role: activeFilter.value === "All" ? "none" : "tabpanel"
					}, null, 8, [
						"id",
						"content",
						"data",
						"headers",
						"role"
					])) : (openBlock(), createBlock(ResponseBody_default, {
						key: 2,
						class: "response-section-content-body",
						id: filterIds.value.Body,
						layout: "client",
						active: true,
						data: __props.response?.data,
						headers: responseHeaders.value,
						role: activeFilter.value === "All" ? "none" : "tabpanel",
						title: "Body"
					}, null, 8, [
						"id",
						"data",
						"headers",
						"role"
					]))], 64)) : createCommentVNode("", true)
				], 64)), createVNode(ResponseLoadingOverlay_default)], 10, _hoisted_2)]),
				_: 1
			});
		};
	}
});
//#endregion
export { ResponseSection_vue_vue_type_script_setup_true_lang_default as default };

//# sourceMappingURL=ResponseSection.vue.script.js.map