"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var inputParsing_exports = {};
__export(inputParsing_exports, {
  detectAutocompleteType: () => detectAutocompleteType,
  extractResourceQuery: () => extractResourceQuery,
  extractSlashQuery: () => extractSlashQuery,
  findActiveAtIndex: () => findActiveAtIndex,
  parseInput: () => import_command_parser.parseInput
});
module.exports = __toCommonJS(inputParsing_exports);
var import_command_parser = require("../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;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  detectAutocompleteType,
  extractResourceQuery,
  extractSlashQuery,
  findActiveAtIndex,
  parseInput
});
