import { logger } from "../../../logger/index.js";
import { GithubTagsDatasource } from "../../datasource/github-tags/index.js";
import { GiteaTagsDatasource } from "../../datasource/gitea-tags/index.js";
import { GitlabTagsDatasource } from "../../datasource/gitlab-tags/index.js";
import { parsePreset } from "../../../config/presets/parse.js";
import { RenovateJson } from "./schema.js";
import { isNonEmptyArray, isNullOrUndefined } from "@sindresorhus/is";
//#region lib/modules/manager/renovate-config-presets/extract.ts
const supportedPresetSources = {
	github: GithubTagsDatasource.id,
	gitlab: GitlabTagsDatasource.id,
	gitea: GiteaTagsDatasource.id
};
function extractPackageFile(content, packageFile) {
	logger.trace(`renovate-config-presets.extractPackageFile(${packageFile})`);
	const config = RenovateJson.safeParse(content);
	if (!config.success) {
		logger.debug({
			packageFile,
			err: config.error
		}, "Invalid Renovate Config");
		return null;
	}
	const deps = [];
	for (const preset of config.data.extends ?? []) {
		const parsedPreset = parsePreset(preset);
		const datasource = supportedPresetSources[parsedPreset.presetSource];
		if (isNullOrUndefined(datasource)) {
			if (parsedPreset.presetSource !== "internal") deps.push({
				depName: parsedPreset.repo,
				skipReason: "unsupported-datasource"
			});
			continue;
		}
		if (isNullOrUndefined(parsedPreset.tag)) {
			deps.push({
				depName: parsedPreset.repo,
				skipReason: "unspecified-version"
			});
			continue;
		}
		deps.push({
			depName: parsedPreset.repo,
			datasource,
			currentValue: parsedPreset.tag
		});
	}
	return isNonEmptyArray(deps) ? { deps } : null;
}
//#endregion
export { extractPackageFile };

//# sourceMappingURL=extract.js.map