import { getSnippet } from "./helpers/get-snippet.js";
import { getHarRequest } from "./helpers/get-har-request.js";
import { computed, createBlock, createCommentVNode, createElementBlock, defineComponent, openBlock, toDisplayString, unref } from "vue";
import { ScalarCodeBlock } from "@scalar/components";
import { isDefined } from "@scalar/oas-utils/helpers";
import { encode } from "js-base64";
//#region src/views/Components/CodeSnippet/CodeSnippet.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1 = {
	key: 0,
	class: "text-c-3 flex min-h-16 items-center justify-center px-4 text-sm"
};
var CodeSnippet_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
	__name: "CodeSnippet",
	props: {
		target: {},
		client: {},
		operation: {},
		server: {},
		example: {},
		securitySchemes: { default: () => [] },
		environment: {}
	},
	setup(__props) {
		/**  Block secrets from being shown in the code block */
		const secretCredentials = computed(() => __props.securitySchemes.flatMap((scheme) => {
			if (scheme.type === "apiKey") return scheme.value;
			if (scheme?.type === "http") return [
				scheme.token,
				scheme.password,
				encode(`${scheme.username}:${scheme.password}`)
			];
			if (scheme.type === "oauth2") return Object.values(scheme.flows).map((flow) => flow?.token).filter(isDefined);
			return [];
		}));
		/** Generated code example */
		const content = computed(() => {
			const harRequest = getHarRequest({
				operation: __props.operation,
				example: __props.example,
				server: __props.server,
				securitySchemes: __props.securitySchemes,
				environment: __props.environment
			});
			const [error, payload] = getSnippet(__props.target, __props.client, harRequest);
			return {
				error,
				payload
			};
		});
		/** CodeMirror syntax highlighting language */
		const language = computed(() => {
			if (__props.target === "shell" && __props.client === "curl") return "curl";
			return __props.target ?? "plaintext";
		});
		return (_ctx, _cache) => {
			return content.value.error ? (openBlock(), createElementBlock("div", _hoisted_1, toDisplayString(content.value.error.message), 1)) : content.value.payload ? (openBlock(), createBlock(unref(ScalarCodeBlock), {
				key: 1,
				class: "w-full",
				content: content.value.payload,
				hideCredentials: secretCredentials.value,
				lang: language.value,
				lineNumbers: ""
			}, null, 8, [
				"content",
				"hideCredentials",
				"lang"
			])) : createCommentVNode("", true);
		};
	}
});
//#endregion
export { CodeSnippet_vue_vue_type_script_setup_true_lang_default as default };

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