//#region ../@intlayer/cli/dist/esm/translation-alignment/rebuildDocument.mjs
/**
* Analyzes the alignment plan and returns only the segments that need review/translation.
* Does not generate output text - that's done by mergeReviewedSegments after translation.
*/
const identifySegmentsToReview = ({ englishBlocks, frenchBlocks, plan }) => {
	const segmentsToReview = [];
	plan.actions.forEach((action, actionIndex) => {
		if (action.kind === "review") {
			const englishBlock = englishBlocks[action.englishIndex];
			const frenchBlockText = action.frenchIndex !== null ? frenchBlocks[action.frenchIndex].content : null;
			segmentsToReview.push({
				englishBlock,
				frenchBlockText,
				actionIndex
			});
		} else if (action.kind === "insert_new") {
			const englishBlock = englishBlocks[action.englishIndex];
			segmentsToReview.push({
				englishBlock,
				frenchBlockText: null,
				actionIndex
			});
		}
	});
	return { segmentsToReview };
};
/**
* Merges reviewed translations back into the final document following the alignment plan.
*/
const mergeReviewedSegments = (plan, frenchBlocks, reviewedSegments) => {
	const outputParts = [];
	plan.actions.forEach((action, actionIndex) => {
		if (action.kind === "reuse") outputParts.push(frenchBlocks[action.frenchIndex].content);
		else if (action.kind === "review" || action.kind === "insert_new") {
			const reviewedContent = reviewedSegments.get(actionIndex);
			if (reviewedContent !== void 0) outputParts.push(reviewedContent);
			else if (action.kind === "review" && action.frenchIndex !== null) outputParts.push(frenchBlocks[action.frenchIndex].content);
			else outputParts.push("\n");
		}
	});
	return outputParts.join("");
};

//#endregion
export { identifySegmentsToReview, mergeReviewedSegments };
//# sourceMappingURL=rebuildDocument.mjs.map