"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var command_parser_exports = {};
__export(command_parser_exports, {
  displayAllCommands: () => displayAllCommands,
  formatCommandHelp: () => formatCommandHelp,
  getCommandSuggestions: () => getCommandSuggestions,
  overlayOnlyHandler: () => overlayOnlyHandler,
  parseInput: () => parseInput
});
module.exports = __toCommonJS(command_parser_exports);
var import_chalk = __toESM(require("chalk"), 1);
const overlayOnlyHandler = async () => true;
function parseQuotedArguments(input) {
  const args = [];
  let current = "";
  let inQuotes = false;
  let quoteChar = "";
  let i = 0;
  while (i < input.length) {
    const char = input[i];
    const nextChar = input[i + 1];
    if (!inQuotes && (char === '"' || char === "'")) {
      inQuotes = true;
      quoteChar = char;
    } else if (inQuotes && char === quoteChar) {
      inQuotes = false;
      quoteChar = "";
    } else if (!inQuotes && char === " ") {
      if (current) {
        args.push(current);
        current = "";
      }
    } else if (char === "\\" && nextChar) {
      current += nextChar;
      i++;
    } else {
      current += char;
    }
    i++;
  }
  if (current) {
    args.push(current);
  }
  return args.filter((arg) => arg.length > 0);
}
function parseInput(input) {
  const trimmed = input.trim();
  if (trimmed.startsWith("!")) {
    const shellCommand = trimmed.slice(1).trim();
    return {
      type: "command",
      command: "shell",
      args: [shellCommand],
      rawInput: trimmed
    };
  }
  if (trimmed.startsWith("/")) {
    const args = parseQuotedArguments(trimmed.slice(1));
    const command = args[0] || "";
    const commandArgs = args.slice(1);
    return {
      type: "command",
      command,
      args: commandArgs,
      rawInput: trimmed
    };
  }
  return {
    type: "prompt",
    rawInput: input
  };
}
function getCommandSuggestions(partial, commands) {
  const suggestions = [];
  for (const cmd of commands) {
    if (cmd.name.startsWith(partial)) {
      suggestions.push(cmd.name);
    }
    if (cmd.aliases) {
      for (const alias of cmd.aliases) {
        if (alias.startsWith(partial)) {
          suggestions.push(alias);
        }
      }
    }
  }
  return suggestions.sort();
}
function formatCommandHelp(cmd, detailed = false) {
  let help = import_chalk.default.cyan(`/${cmd.name}`) + " - " + cmd.description;
  if (detailed) {
    help += "\n" + import_chalk.default.gray(`Usage: ${cmd.usage}`);
    if (cmd.aliases && cmd.aliases.length > 0) {
      help += "\n" + import_chalk.default.gray(`Aliases: ${cmd.aliases.map((a) => `/${a}`).join(", ")}`);
    }
    if (cmd.subcommands && cmd.subcommands.length > 0) {
      help += "\n" + import_chalk.default.gray("Subcommands:");
      for (const sub of cmd.subcommands) {
        help += "\n  " + import_chalk.default.cyan(`/${cmd.name} ${sub.name}`) + " - " + sub.description;
      }
    }
  }
  return help;
}
function displayAllCommands(commands) {
  console.log(import_chalk.default.bold.green("\n\u{1F4CB} Available Commands:\n"));
  const categoryOrder = [
    "General",
    "Session Management",
    "Model Management",
    "MCP Management",
    "Plugin Management",
    "Tool Management",
    "Prompt Management",
    "Skill Management",
    "System"
  ];
  const categories = {};
  for (const category of categoryOrder) {
    categories[category] = [];
  }
  for (const cmd of commands) {
    const category = cmd.category || "General";
    if (!categories[category]) {
      categories[category] = [];
    }
    categories[category].push(cmd);
  }
  for (const category of categoryOrder) {
    const cmds = categories[category];
    if (cmds && cmds.length > 0) {
      console.log(import_chalk.default.bold.rgb(255, 165, 0)(`${category}:`));
      for (const cmd of cmds) {
        console.log("  " + formatCommandHelp(cmd));
      }
      console.log();
    }
  }
  for (const [category, cmds] of Object.entries(categories)) {
    if (!categoryOrder.includes(category) && cmds.length > 0) {
      console.log(import_chalk.default.bold.rgb(255, 165, 0)(`${category}:`));
      for (const cmd of cmds) {
        console.log("  " + formatCommandHelp(cmd));
      }
      console.log();
    }
  }
  console.log(import_chalk.default.gray("\u{1F4A1} Tip: Use /help <command> for detailed help on any command"));
  console.log(import_chalk.default.gray("\u{1F4A1} Tip: Type your message normally (without /) to chat with the AI\n"));
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  displayAllCommands,
  formatCommandHelp,
  getCommandSuggestions,
  overlayOnlyHandler,
  parseInput
});
