import { snippetz } from "@scalar/snippetz";
//#region src/views/Components/CodeSnippet/helpers/get-snippet.ts
/** Key used to hack around the invalid urls */
var INVALID_URLS_PREFIX = "ws://replace.me";
/**
* Returns a code example for given operation
*/
var getSnippet = (target, client, harRequest) => {
	try {
		if (!harRequest.url) return [/* @__PURE__ */ new Error("Please enter a URL to see a code snippet"), null];
		const separator = harRequest.url.startsWith("/") ? "" : "/";
		try {
			new URL(harRequest.url);
		} catch (error) {
			console.error("[getSnippet] Invalid URL", error);
			harRequest.url = `${INVALID_URLS_PREFIX}${separator}${harRequest.url}`;
		}
		if (harRequest.postData?.mimeType === "application/json") try {
			JSON.parse(harRequest.postData.text || "{}");
		} catch (error) {
			console.error("[getSnippet] Invalid JSON body", error);
			return [/* @__PURE__ */ new Error("Invalid JSON body"), null];
		}
		const snippetzTargetKey = target.replace("javascript", "js");
		if (snippetz().hasPlugin(snippetzTargetKey, client)) {
			const payload = snippetz().print(snippetzTargetKey, client, harRequest);
			if (!payload) return [/* @__PURE__ */ new Error("Error generating snippet"), null];
			return [null, payload.replace(`${INVALID_URLS_PREFIX}${separator}`, "")];
		}
	} catch (error) {
		console.error("[getSnippet] Error generating snippet", error);
		return [/* @__PURE__ */ new Error("Error generating snippet"), null];
	}
	return [/* @__PURE__ */ new Error("No snippet found"), null];
};
//#endregion
export { getSnippet as t };

//# sourceMappingURL=get-snippet-DBRUSfZ2.js.map