import { COAUTHOR_ACTIONS, isCoauthorAction } from './coauthor-client.js';
const SLASH_HEAD = /^\s*\/\s*ai(?:\s+|$)/i;
/**
 * Returns the matched `{ action, text }` when `input` is a complete
 * slash command (`/ai rewrite ...`), or `null` otherwise. `text` may be
 * empty when the user has typed `/ai rewrite` with no payload yet.
 */
export function parseAiSlashCommand(input) {
    if (typeof input !== 'string')
        return null;
    if (!SLASH_HEAD.test(input))
        return null;
    const after = input.replace(SLASH_HEAD, '');
    if (after.length === 0)
        return null;
    const firstWhitespace = after.search(/\s/);
    const head = (firstWhitespace === -1 ? after : after.slice(0, firstWhitespace)).toLowerCase();
    if (!isCoauthorAction(head))
        return null;
    const tail = firstWhitespace === -1 ? '' : after.slice(firstWhitespace + 1);
    return { action: head, text: tail.trim() };
}
/**
 * Returns true when `input` looks like the start of an AI slash command
 * — even when the action isn't typed yet (`/`, `/a`, `/ai`, `/ai re`).
 * The palette uses this to switch into "AI mode" (hide nav results,
 * show the four action suggestions).
 */
export function isAiSlashCommandInput(input) {
    if (typeof input !== 'string')
        return false;
    const trimmed = input.trim();
    if (trimmed.length === 0)
        return false;
    if (trimmed === '/')
        return true;
    return /^\/\s*a(i\b|i?[a-z]*|)?(\s.*)?$/i.test(trimmed);
}
/**
 * Ordered list of actions to show in AI mode. When the user has typed a
 * valid command, that command's action is hoisted to the top so it gets
 * the default keyboard focus (and Enter runs it).
 */
export function orderedAiActions(input) {
    const parsed = parseAiSlashCommand(input);
    if (!parsed)
        return [...COAUTHOR_ACTIONS];
    return [parsed.action, ...COAUTHOR_ACTIONS.filter((a) => a !== parsed.action)];
}
//# sourceMappingURL=slash-command.js.map