// Helpers for keeping a field selected while the user moves focus into the
// agent terminal. A field blur normally clears the focused field, which also
// removes the live "currently viewing" field chip from the agent context bar —
// right when the user clicks the prompt to ask about that field. These helpers
// let the blur guard recognize that the blur was caused by an agent terminal
// interaction.
// How long after an interaction with the agent terminal we still treat a field
// blur as "focus moved to the terminal". A pointer-down (or focusin, for Tab)
// reliably precedes the blur in every path, including the async iframe
// inline-editing bridge hop. Unlike the Show me guard we do NOT sample
// `document.activeElement`: the prompt textarea holds focus for minutes, and a
// persistent activeElement check would suppress legitimate clears (e.g. a mode
// change via keyboard shortcut) while the user types.
export const AGENT_TERMINAL_BLUR_GRACE_MS = 350;
const AGENT_TERMINAL_SELECTOR = "[data-agent-terminal-root]";
/** Whether an event target is (or is inside) the agent terminal. */
export function isAgentTerminalTarget(target) {
    const element = target instanceof Element ? target : null;
    return !!element?.closest(AGENT_TERMINAL_SELECTOR);
}
/**
 * Next value for the "last agent terminal interaction" timestamp given an
 * interaction (pointer-down or focusin) on `target`. Interactions outside the
 * terminal reset the timestamp so the grace window only survives while the
 * LAST interaction was inside the terminal — otherwise a quick terminal focus
 * followed by a click elsewhere would shield that click's legitimate
 * focused-field clear.
 */
export function nextAgentTerminalInteractionAt(target, now) {
    return isAgentTerminalTarget(target) ? now : 0;
}
/**
 * Decide whether a field blur was caused by moving focus into the agent
 * terminal, so the focused field (and its agent context chip) should be kept.
 */
export function isAgentTerminalFocusTransfer(params) {
    const graceMs = params.graceMs ?? AGENT_TERMINAL_BLUR_GRACE_MS;
    return params.now - params.lastAgentTerminalInteractionAt < graceMs;
}
//# sourceMappingURL=agentTerminalFocus.js.map