"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.directCommandCompleter = directCommandCompleter;
const shell_api_1 = require("@mongosh/shell-api");
async function directCommandCompleter(context, line) {
    const SHELL_COMPLETIONS = shell_api_1.signatures.ShellApi
        .attributes;
    const splitLineWhitespace = line.split(/(?<!\S)(?=\S)/);
    const command = splitLineWhitespace[0].trim();
    if (!SHELL_COMPLETIONS[command]?.isDirectShellCommand) {
        return [];
    }
    const completer = SHELL_COMPLETIONS[command].newShellCommandCompleter;
    if (!completer) {
        return [line];
    }
    if (splitLineWhitespace.length === 1) {
        if (splitLineWhitespace[0].trimEnd() === splitLineWhitespace[0]) {
            splitLineWhitespace[0] += ' ';
        }
        splitLineWhitespace.push('');
    }
    const hits = (await completer(context, splitLineWhitespace.map((item) => item.trim()))) || [];
    const fullLineHits = hits.map((hit) => [...splitLineWhitespace.slice(0, -1), hit].join(''));
    return fullLineHits;
}
//# sourceMappingURL=direct-command-completer.js.map