import { APP_VERSION } from "../../constants.js";
import { combineParams } from "./helpers/combine-params.js";
import { getSelectedServer } from "./helpers/get-selected-server.js";
import { mapHiddenClientsConfig } from "../modal/helpers/map-hidden-clients-config.js";
import { getActiveProxyUrl } from "../../helpers/get-active-proxy-url.js";
import { getServers } from "../../helpers/get-servers.js";
import OperationBlock_default from "../../blocks/operation-block/OperationBlock.vue.js";
import { computed, createBlock, createElementBlock, createElementVNode, defineComponent, openBlock, toValue, unref } from "vue";
import { getResolvedRef } from "@scalar/workspace-store/helpers/get-resolved-ref";
//#region src/v2/features/operation/Operation.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1 = {
	key: 1,
	class: "flex h-full w-full items-center justify-center"
};
var Operation_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
	__name: "Operation",
	props: {
		documentSlug: {},
		document: {},
		eventBus: {},
		layout: {},
		path: {},
		method: {},
		exampleName: {},
		environment: {},
		securitySchemes: {},
		workspaceStore: {},
		activeWorkspace: {},
		plugins: {},
		customThemes: {},
		currentTheme: {},
		isDarkMode: { type: Boolean },
		fetchRegistryDocument: { type: Function },
		telemetry: { type: Boolean },
		onUpdateTelemetry: { type: Function },
		options: {},
		requestBodyCompositionSelection: {}
	},
	setup(__props) {
		/** Grab the path item object from the document */
		const pathItem = computed(() => {
			if (!__props.path) return null;
			return getResolvedRef(__props.document?.paths?.[__props.path]);
		});
		/** Find the operation and augment with any path parameters */
		const operation = computed(() => {
			if (!__props.path || !__props.method) return null;
			const operation = getResolvedRef(__props.document?.paths?.[__props.path]?.[__props.method]);
			if (!operation) return null;
			if (!pathItem.value) return operation;
			const parameters = combineParams(pathItem.value.parameters, operation.parameters);
			return {
				...operation,
				parameters
			};
		});
		/** Combine the workspace and document cookies */
		const globalCookies = computed(() => [...(__props.workspaceStore.workspace?.["x-scalar-cookies"] ?? []).map((it) => ({
			...it,
			location: "workspace"
		})), ...(__props.document?.["x-scalar-cookies"] ?? []).map((it) => ({
			...it,
			location: "document"
		}))]);
		/** Compute the servers for the operation */
		const servers = computed(() => {
			return getServers(toValue(__props.options)?.servers ?? operation.value?.servers ?? __props.document?.servers, {
				baseServerUrl: toValue(__props.options)?.baseServerURL,
				documentUrl: __props.document?.["x-scalar-original-source-url"]
			});
		});
		/** Selected server URL from the same source as servers: operation, then document (config has no stored selection so use document selection) */
		const selectedServerUrl = computed(() => {
			if (toValue(__props.options)?.servers != null) return __props.document?.["x-scalar-selected-server"];
			if (operation.value?.servers != null) return operation.value["x-scalar-selected-server"];
			return __props.document?.["x-scalar-selected-server"];
		});
		/** Selected server for the operation (document-level or operation-level servers) */
		const selectedServer = computed(() => getSelectedServer(servers.value, selectedServerUrl.value));
		const serverMeta = computed(() => {
			if (operation.value?.servers != null) return {
				type: "operation",
				path: __props.path ?? "",
				method: __props.method ?? "get"
			};
			return { type: "document" };
		});
		const documentSelectedSecurity = computed(() => {
			return __props.workspaceStore.auth.getAuthSelectedSchemas({
				type: "document",
				documentName: __props.documentSlug
			});
		});
		const operationSelectedSecurity = computed(() => {
			return __props.workspaceStore.auth.getAuthSelectedSchemas({
				type: "operation",
				documentName: __props.documentSlug,
				path: __props.path ?? "",
				method: __props.method ?? "get"
			});
		});
		/** Select document vs operation meta based on the extension */
		const authMeta = computed(() => {
			if (operationSelectedSecurity.value !== void 0) return {
				type: "operation",
				path: __props.path ?? "",
				method: __props.method ?? "get"
			};
			return { type: "document" };
		});
		/** Combine environments from document and workspace into a unique array of environment names */
		const environments = computed(() => {
			return Array.from(new Set(Object.keys({
				...__props.document?.["x-scalar-environments"],
				...__props.workspaceStore.workspace["x-scalar-environments"]
			})));
		});
		/** Temporarily use the old config.hiddenClients until we migrate to the new httpClients config */
		const httpClients = computed(() => mapHiddenClientsConfig(toValue(__props.options)?.hiddenClients));
		return (_ctx, _cache) => {
			return __props.path && __props.method && __props.exampleName && operation.value ? (openBlock(), createBlock(unref(OperationBlock_default), {
				key: 0,
				activeEnvironment: __props.workspaceStore.workspace["x-scalar-active-environment"],
				appVersion: unref(APP_VERSION),
				authMeta: authMeta.value,
				documentSecurity: __props.document?.security ?? [],
				documentSelectedSecurity: documentSelectedSecurity.value,
				documentUrl: __props.document?.["x-scalar-original-source-url"],
				environment: __props.environment,
				environments: environments.value,
				eventBus: __props.eventBus,
				exampleKey: __props.exampleName,
				globalCookies: globalCookies.value,
				hideClientButton: toValue(__props.options)?.hideClientButton ?? false,
				history: __props.workspaceStore.history.getHistory(__props.documentSlug, __props.path, __props.method),
				httpClients: httpClients.value,
				layout: __props.layout,
				method: __props.method,
				operation: operation.value,
				operationSelectedSecurity: operationSelectedSecurity.value,
				path: __props.path,
				plugins: __props.plugins,
				proxyUrl: unref(getActiveProxyUrl)(__props.workspaceStore.workspace["x-scalar-active-proxy"], __props.layout) ?? "",
				requestBodyCompositionSelection: __props.requestBodyCompositionSelection,
				securitySchemes: __props.securitySchemes,
				selectedClient: __props.workspaceStore.workspace["x-scalar-default-client"],
				server: selectedServer.value,
				serverMeta: serverMeta.value,
				servers: servers.value
			}, null, 8, [
				"activeEnvironment",
				"appVersion",
				"authMeta",
				"documentSecurity",
				"documentSelectedSecurity",
				"documentUrl",
				"environment",
				"environments",
				"eventBus",
				"exampleKey",
				"globalCookies",
				"hideClientButton",
				"history",
				"httpClients",
				"layout",
				"method",
				"operation",
				"operationSelectedSecurity",
				"path",
				"plugins",
				"proxyUrl",
				"requestBodyCompositionSelection",
				"securitySchemes",
				"selectedClient",
				"server",
				"serverMeta",
				"servers"
			])) : (openBlock(), createElementBlock("div", _hoisted_1, [..._cache[0] || (_cache[0] = [createElementVNode("span", { class: "text-c-3" }, "Select an operation to view details", -1)])]));
		};
	}
});
//#endregion
export { Operation_vue_vue_type_script_setup_true_lang_default as default };

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