"use strict";

module.exports = function stripPlaintextReplyFallback(plaintext) {
	let lines = plaintext.split("\n");
	let firstNonReplyLine = lines.findIndex((line) => !line.startsWith("> "));

	if (firstNonReplyLine !== -1) {
		let nonReplyLines = lines.slice(firstNonReplyLine);
		let firstNonEmptyLine = nonReplyLines.findIndex((line) => line.length > 0);

		if (firstNonEmptyLine !== -1) {
			let nonEmptyLines = nonReplyLines.slice(firstNonEmptyLine);
			return nonEmptyLines.join("\n");
		} else {
			return "";
		}
	} else {
		return "";
	}
};
