import { regEx } from "../../../../util/regex.js";
import { logger } from "../../../../logger/index.js";
import { emojify } from "../../../../util/emoji.js";

//#region lib/workers/repository/onboarding/pr/pr-list.ts
function getExpectedPrList(config, branches) {
	logger.debug("getExpectedPrList()");
	logger.trace({ config });
	let prDesc = `\n### What to Expect\n\n`;
	if (!branches.length) return `${prDesc}It looks like your repository dependencies are already up-to-date and no Pull Requests will be necessary right away.\n`;
	prDesc += `With your current configuration, Renovate will create ${branches.length} Pull Request`;
	prDesc += branches.length > 1 ? `s:\n\n` : `:\n\n`;
	for (const branch of branches) {
		const prTitleRe = regEx(/@([a-z]+\/[a-z]+)/);
		prDesc += `<details>\n<summary>${branch.prTitle.replace(prTitleRe, "@&#8203;$1")}</summary>\n\n`;
		if (branch.schedule?.length) prDesc += `  - Schedule: ${JSON.stringify(branch.schedule)}\n`;
		prDesc += `  - Branch name: \`${branch.branchName}\`\n`;
		prDesc += branch.baseBranch ? `  - Merge into: \`${branch.baseBranch}\`\n` : "";
		const seen = [];
		for (const upgrade of branch.upgrades) {
			let text = "";
			if (upgrade.updateType === "lockFileMaintenance") text += "  - Regenerate lock files to use latest dependency versions";
			else {
				if (upgrade.updateType === "pin") text += "  - Pin ";
				else text += "  - Upgrade ";
				if (upgrade.sourceUrl) text += `[${upgrade.depName}](${upgrade.sourceUrl})`;
				else text += upgrade.depName.replace(prTitleRe, "@&#8203;$1");
				text += upgrade.isLockfileUpdate ? ` to \`${upgrade.newVersion}\`` : ` to \`${upgrade.newDigest ?? upgrade.newValue}\``;
				text += "\n";
			}
			if (!seen.includes(text)) {
				prDesc += text;
				seen.push(text);
			}
		}
		prDesc += "\n\n";
		prDesc += "</details>\n\n";
	}
	const prHourlyLimit = config.prHourlyLimit;
	if (prHourlyLimit > 0 && prHourlyLimit < 5 && prHourlyLimit < branches.length) prDesc += emojify(`\n\n:children_crossing: Branch creation will be limited to maximum ${prHourlyLimit} per hour, so it doesn't swamp any CI resources or overwhelm the project. See docs for \`prHourlyLimit\` for details.\n\n`);
	return prDesc;
}

//#endregion
export { getExpectedPrList };
//# sourceMappingURL=pr-list.js.map