"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildFollowupRequestHeadingLine = buildFollowupRequestHeadingLine;
exports.extractFollowupRequestSectionText = extractFollowupRequestSectionText;
exports.isDefaultFollowupRequestText = isDefaultFollowupRequestText;
const catalog_1 = require("../i18n/catalog");
const FOLLOWUP_REQUEST_HEADING_KEY = "run.followup.body.requestHeading";
const FOLLOWUP_DEFAULT_REQUEST_KEY = "run.followup.body.defaultRequest";
const FOLLOWUP_REQUEST_HEADING_LINES = new Set((0, catalog_1.translateAllLocales)(FOLLOWUP_REQUEST_HEADING_KEY).map((heading) => `## ${heading}`));
const FOLLOWUP_DEFAULT_REQUEST_TEXTS = new Set((0, catalog_1.translateAllLocales)(FOLLOWUP_DEFAULT_REQUEST_KEY).map((text) => normalizeFollowupRequestText(text)));
function buildFollowupRequestHeadingLine(locale) {
    return `## ${(0, catalog_1.translate)(locale, FOLLOWUP_REQUEST_HEADING_KEY)}`;
}
function extractFollowupRequestSectionText(body) {
    const text = body.trim();
    if (text.length === 0) {
        return null;
    }
    const lines = text.split(/\r?\n/u);
    const headingIndex = lines.findIndex((line) => FOLLOWUP_REQUEST_HEADING_LINES.has(line.trim()));
    if (headingIndex === -1) {
        return null;
    }
    const nextHeadingIndex = lines.findIndex((line, index) => index > headingIndex && /^##\s/u.test(line));
    const sectionEndIndex = nextHeadingIndex === -1 ? lines.length : nextHeadingIndex;
    const sectionText = lines.slice(headingIndex + 1, sectionEndIndex).join("\n");
    return sectionText.trim().length === 0 ? null : sectionText.trim();
}
function isDefaultFollowupRequestText(text) {
    return FOLLOWUP_DEFAULT_REQUEST_TEXTS.has(normalizeFollowupRequestText(text));
}
function normalizeFollowupRequestText(text) {
    return text.trim().replace(/\s+/gu, " ");
}
