import { formatI18n } from "../../i18n/format.js";
import { SERVER_LOCALES, isServerLocale, normalizeServerLocale, serverLocaleOrFallback } from "../../i18n/locale.js";
import { checklistCounts } from "./checklist-types.js";
import { PERSISTENT_GOAL_CUSTOM_KEY, mergeCustomDataPatch, readPersistentGoal, renderChecklistPlain, serializePersistentGoal } from "./state.js";
import { JUDGE_REASON_EN, goalsChecklistProgressSuffix, goalsContinuationChecklistTemplate, goalsContinuationPlainTemplate, goalsEvaluateCopy, goalsJudgeReason, goalsJudgeResponseLanguageNote } from "../../i18n/goals-bundle.js";
//#region src/agent/goals/goal-locale.ts
const GOAL_UI_LOCALES = SERVER_LOCALES;
const DEFAULT_GOAL_UI_LOCALE = "en";
const isGoalUiLocale = isServerLocale;
const normalizeGoalUiLocale = normalizeServerLocale;
const goalUiLocaleOrFallback = serverLocaleOrFallback;
function resolveGoalUiLocale(state) {
	return goalUiLocaleOrFallback(state?.uiLocale);
}
const CONTINUATION_PROMPT_TEMPLATE_EN = goalsContinuationPlainTemplate("en");
const CONTINUATION_PROMPT_WITH_CHECKLIST_TEMPLATE_EN = goalsContinuationChecklistTemplate("en");
function buildContinuationPromptFromState(state, locale) {
	const L = goalUiLocaleOrFallback(locale);
	const cl = state.checklist ?? [];
	if (cl.length) {
		const plain = renderChecklistPlain(cl);
		const { total, completed, impossible } = checklistCounts(cl);
		const done = completed + impossible;
		return formatI18n(goalsContinuationChecklistTemplate(L), {
			goal: state.goal,
			done,
			total,
			checklist: plain
		});
	}
	return formatI18n(goalsContinuationPlainTemplate(L), { goal: state.goal });
}
function judgeResponseLanguageNote(locale) {
	return goalsJudgeResponseLanguageNote(goalUiLocaleOrFallback(locale));
}
const JUDGE_REASON_ID_BY_EN = new Map(Object.entries(JUDGE_REASON_EN).map(([id, s]) => [s, id]));
function judgeReasonText(id, locale) {
	return goalsJudgeReason(id, goalUiLocaleOrFallback(locale));
}
function localizeJudgeReasonText(reason, locale) {
	const id = JUDGE_REASON_ID_BY_EN.get(reason);
	if (!id) return reason;
	return judgeReasonText(id, locale);
}
function judgeFreeformBuiltinMessages(locale) {
	const L = goalUiLocaleOrFallback(locale);
	return {
		emptyGoal: judgeReasonText("empty_goal", L),
		emptyResponse: judgeReasonText("empty_response", L),
		noModel: judgeReasonText("judge_model_not_configured", L),
		callFailed: judgeReasonText("judge_call_failed", L)
	};
}
function checklistProgressSuffix(done, total, locale) {
	return goalsChecklistProgressSuffix(done, total, goalUiLocaleOrFallback(locale));
}
function goalEvaluateUserCopy(locale) {
	return goalsEvaluateCopy(goalUiLocaleOrFallback(locale));
}
/** Persist `uiLocale` on the standing goal when the gateway console language is known. */
function mergePersistentGoalUiLocale(customData, locale) {
	if (!locale) return customData;
	const canonical = goalUiLocaleOrFallback(locale);
	const g = readPersistentGoal(customData);
	if (!g || g.status === "cleared") return customData;
	if (g.uiLocale === canonical) return customData;
	const next = {
		...g,
		uiLocale: canonical
	};
	return mergeCustomDataPatch(customData ?? {}, { [PERSISTENT_GOAL_CUSTOM_KEY]: serializePersistentGoal(next) });
}
//#endregion
export { CONTINUATION_PROMPT_TEMPLATE_EN, CONTINUATION_PROMPT_WITH_CHECKLIST_TEMPLATE_EN, DEFAULT_GOAL_UI_LOCALE, GOAL_UI_LOCALES, JUDGE_REASON_EN, buildContinuationPromptFromState, checklistProgressSuffix, goalEvaluateUserCopy, goalUiLocaleOrFallback, isGoalUiLocale, judgeFreeformBuiltinMessages, judgeReasonText, judgeResponseLanguageNote, localizeJudgeReasonText, mergePersistentGoalUiLocale, normalizeGoalUiLocale, resolveGoalUiLocale };

//# sourceMappingURL=goal-locale.js.map