const MODES = new Set(["self", "smoke", "google", "browser", "cua", "cleanup", "setup", "help"]);
export function parseE2EArgs(args) {
    const filtered = args.filter((arg) => arg.trim() !== "");
    const flags = new Set(filtered.filter((arg) => arg.startsWith("--")));
    const positional = filtered.filter((arg) => !arg.startsWith("--"));
    const first = positional[0];
    if (first && !MODES.has(first)) {
        throw new Error(`Unknown e2e mode: ${first}`);
    }
    const mode = first ? first : "smoke";
    let setupKind;
    let cleanupTarget;
    if (mode === "setup") {
        if (positional[1] === "google-guest")
            setupKind = "google-guest";
        if (positional[1] === "google-guest-code")
            setupKind = "google-guest-code";
    }
    if (mode === "cleanup") {
        cleanupTarget = positional[1];
    }
    return {
        mode,
        args: positional,
        flags,
        json: flags.has("--json"),
        autoCleanup: flags.has("--auto-cleanup"),
        includeDestructive: flags.has("--include-destructive"),
        setupKind,
        cleanupTarget,
    };
}
export function parseE2ECommandText(text) {
    const match = /^\/e2e(?:@\S+)?(?:\s+(.*))?$/i.exec(text.trim());
    if (!match) {
        throw new Error("Invalid /e2e command");
    }
    return parseE2EArgs(splitCommandArgs(match[1] || ""));
}
function splitCommandArgs(input) {
    const args = [];
    const pattern = /"([^"]*)"|'([^']*)'|(\S+)/g;
    let match;
    while ((match = pattern.exec(input)) !== null) {
        const token = match[1] || match[2] || match[3];
        if (token)
            args.push(token);
    }
    return args;
}
//# sourceMappingURL=parser.js.map