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

//#region lib/modules/platform/utils/pr-body.ts
const re = regEx(`(?<preNotes>.*### Release Notes)(?<releaseNotes>.*)### Configuration(?<postNotes>.*)`, "s");
function smartTruncate(input, len) {
	if (input.length < len) return input;
	logger.debug(`Truncating PR body due to platform limitation of ${len} characters`);
	const truncatedInput = emojify(`> :information_source: **Note**\n> \n> This PR body was truncated due to platform limits.\n\n`) + input;
	const reMatch = re.exec(truncatedInput);
	if (!reMatch?.groups) return truncatedInput.substring(0, len);
	const divider = `\n\n</details>\n\n---\n\n### Configuration`;
	const preNotes = reMatch.groups.preNotes;
	const releaseNotes = reMatch.groups.releaseNotes;
	const postNotes = reMatch.groups.postNotes;
	const availableLength = len - (preNotes.length + postNotes.length + divider.length);
	if (availableLength <= 0) return truncatedInput.substring(0, len);
	else return preNotes + releaseNotes.slice(0, availableLength) + divider + postNotes;
}

//#endregion
export { smartTruncate };
//# sourceMappingURL=pr-body.js.map