import { parseInput } from "../interactive-commands/command-parser.js";
function detectAutocompleteType(input) {
  if (input.startsWith("/")) {
    const afterSlash = input.slice(1).trim();
    if (afterSlash.includes(" ")) {
      return "none";
    }
    return "slash";
  }
  const atIndex = findActiveAtIndex(input, input.length);
  if (atIndex >= 0) {
    return "resource";
  }
  return "none";
}
function extractSlashQuery(input) {
  if (!input.startsWith("/")) return "";
  return input.slice(1).trim();
}
function extractResourceQuery(input) {
  const atIndex = findActiveAtIndex(input, input.length);
  if (atIndex < 0) return "";
  return input.slice(atIndex + 1).trim();
}
function findActiveAtIndex(value, caret) {
  for (let i = caret - 1; i >= 0; i--) {
    const ch = value[i];
    if (ch === "@") {
      if (i === 0) {
        return i;
      }
      const prev = value[i - 1];
      if (prev && /\s/.test(prev)) {
        return i;
      }
      return -1;
    }
    if (ch && /\s/.test(ch)) break;
  }
  return -1;
}
export {
  detectAutocompleteType,
  extractResourceQuery,
  extractSlashQuery,
  findActiveAtIndex,
  parseInput
};
