import { operationToHar } from "./operation-to-har/operation-to-har.js";
import { generateCustomId } from "./generate-client-options.js";
import { getSnippet } from "../../../../views/Components/CodeSnippet/helpers/get-snippet.js";
//#region src/v2/blocks/operation-code-sample/helpers/generate-code-snippet.ts
/** Generate the code snippet for the selected example OR operation */
var generateCodeSnippet = ({ clientId, customCodeSamples, includeDefaultHeaders = false, operation, method, path, example, contentType, server, securitySchemes, globalCookies, requestBodyCompositionSelection }) => {
	try {
		if (!clientId) return "";
		if (clientId.startsWith("custom")) return customCodeSamples.find((example) => generateCustomId(example) === clientId)?.source ?? "Custom example not found";
		const harRequest = operationToHar({
			operation,
			contentType,
			method,
			path,
			server,
			securitySchemes,
			example,
			globalCookies,
			includeDefaultHeaders,
			requestBodyCompositionSelection
		});
		const [targetKey, clientKey] = clientId.split("/");
		const [error, payload] = getSnippet(targetKey, clientKey, harRequest);
		if (error) {
			console.error("[generateCodeSnippet]", error);
			return error.message ?? "Error generating code snippet";
		}
		return payload;
	} catch (error) {
		console.error("[generateCodeSnippet]", error);
		return "Error generating code snippet";
	}
};
//#endregion
export { generateCodeSnippet };

//# sourceMappingURL=generate-code-snippet.js.map