//#region src/tui/tui-submit.ts
/**
* Submit handling aligned with openclaw: `!` local shell lines + paste burst coalescing
* for terminals that split multiline paste into rapid single-line submits.
*/
function normalizeLowercaseStringOrEmpty(value) {
	return value.trim().toLowerCase();
}
function createEditorSubmitHandler(params) {
	return (text) => {
		const raw = text;
		const value = raw.trim();
		params.editor.setText("");
		if (!value) return;
		if (raw.startsWith("!") && raw !== "!") {
			params.editor.addToHistory(raw);
			params.handleBangLine(raw);
			return;
		}
		params.editor.addToHistory(value);
		if (value.startsWith("/")) {
			params.handleCommand(value);
			return;
		}
		if (params.isAgentBusy?.() && params.steerWhileBusy) {
			params.steerWhileBusy(value);
			return;
		}
		params.sendMessage(value);
	};
}
function shouldEnableWindowsGitBashPasteFallback(params) {
	const platform = params?.platform ?? process.platform;
	const env = params?.env ?? process.env;
	const termProgram = normalizeLowercaseStringOrEmpty(env.TERM_PROGRAM ?? "");
	if (platform === "darwin") {
		if (termProgram.includes("iterm") || termProgram.includes("apple_terminal")) return true;
		return false;
	}
	if (platform !== "win32") return false;
	const msystem = (env.MSYSTEM ?? "").toUpperCase();
	const shell = env.SHELL ?? "";
	if (msystem.startsWith("MINGW") || msystem.startsWith("MSYS")) return true;
	if (normalizeLowercaseStringOrEmpty(shell).includes("bash")) return true;
	return termProgram.includes("mintty");
}
function createSubmitBurstCoalescer(params) {
	const windowMs = Math.max(1, params.burstWindowMs ?? 50);
	const now = params.now ?? (() => Date.now());
	const setTimer = params.setTimer ?? setTimeout;
	const clearTimer = params.clearTimer ?? clearTimeout;
	let pending = null;
	let pendingAt = 0;
	let flushTimer = null;
	const clearFlushTimer = () => {
		if (!flushTimer) return;
		clearTimer(flushTimer);
		flushTimer = null;
	};
	const flushPending = () => {
		if (pending === null) return;
		const flushed = pending;
		pending = null;
		pendingAt = 0;
		clearFlushTimer();
		params.submit(flushed);
	};
	const scheduleFlush = () => {
		clearFlushTimer();
		flushTimer = setTimer(() => {
			flushPending();
		}, windowMs);
	};
	return (value) => {
		if (!params.enabled) {
			params.submit(value);
			return;
		}
		if (value.includes("\n")) {
			flushPending();
			params.submit(value);
			return;
		}
		const ts = now();
		if (pending === null) {
			pending = value;
			pendingAt = ts;
			scheduleFlush();
			return;
		}
		if (ts - pendingAt <= windowMs) {
			pending = `${pending}\n${value}`;
			pendingAt = ts;
			scheduleFlush();
			return;
		}
		flushPending();
		pending = value;
		pendingAt = ts;
		scheduleFlush();
	};
}
//#endregion
export { createEditorSubmitHandler, createSubmitBurstCoalescer, shouldEnableWindowsGitBashPasteFallback };

//# sourceMappingURL=tui-submit.js.map