import { extractSecuritySchemeSecrets } from "./extract-security-scheme-secrets.js";
import { getResolvedRef } from "@scalar/workspace-store/helpers/get-resolved-ref";
import { coerceValue } from "@scalar/workspace-store/schemas/typebox-coerce";
import { objectEntries } from "@scalar/helpers/object/object-entries";
import { SecuritySchemeObjectSchema } from "@scalar/workspace-store/schemas/v3.1/strict/openapi-document";
import { deepClone } from "@scalar/workspace-store/helpers/deep-clone";
import { mergeObjects } from "@scalar/workspace-store/helpers/merge-object";
//#region src/v2/blocks/scalar-auth-selector-block/helpers/merge-security.ts
/** Merge the authentication config with the document security schemes + the auth store secrets */
var mergeSecurity = (documentSecuritySchemes = {}, configSecuritySchemes = {}, authStore, documentSlug) => {
	/** Convert the config secrets to the new secret extensions */
	return objectEntries(mergeObjects(objectEntries(documentSecuritySchemes).reduce((acc, [key, value]) => {
		const resolved = deepClone(getResolvedRef(value));
		if (resolved) acc[key] = resolved;
		return acc;
	}, {}), configSecuritySchemes) ?? {}).reduce((acc, [name, value]) => {
		acc[name] = extractSecuritySchemeSecrets({
			...coerceValue(SecuritySchemeObjectSchema, value),
			...value
		}, authStore, name, documentSlug);
		return acc;
	}, {});
};
//#endregion
export { mergeSecurity };

//# sourceMappingURL=merge-security.js.map