var p = Object.defineProperty;
var s = (e, t) => p(e, "name", { value: t, configurable: !0 });
import { ChangeSet as d, Transaction as l, EditorSelection as h } from "../../../../../@codemirror_state@6.5.2/node_modules/@codemirror/state/dist/index.js";
import { copilotIgnore as g, copilotEvent as f } from "./annotations.js";
import { completionDecoration as i } from "./completionDecoration.js";
import { addSuggestions as S, clearSuggestion as C, acceptSuggestion as x } from "./effects.js";
import { requestCompletion as y } from "./requestCompletion.js";
function T(e) {
  const t = e.state.field(i);
  if (!t)
    return !1;
  const n = t.reverseChangeSet?.invert(e.state.doc);
  e.dispatch({
    changes: t.reverseChangeSet,
    effects: x.of(null),
    annotations: [
      // Tell upstream integrations to ignore this
      // change.
      g.of(null),
      // Tell ourselves not to request a completion
      // because of this change.
      f.of(null),
      // Don't add this to history.
      l.addToHistory.of(!1)
    ]
  });
  let o = 0;
  return n?.iterChangedRanges((c, r, a, u) => {
    o = u;
  }), e.dispatch({
    changes: n,
    selection: h.cursor(o),
    annotations: [f.of(null), l.addToHistory.of(!0)]
  }), !0;
}
s(T, "acceptSuggestionCommand");
const R = /* @__PURE__ */ s((e) => {
  const { state: t } = e, n = t.field(i);
  if (!n)
    return !1;
  const { changeSpecs: o } = n;
  if (o.length < 2)
    return !1;
  const c = (n.index + 1) % o.length, r = o.at(c);
  if (!r)
    return !1;
  const a = n.reverseChangeSet.apply(t.doc), u = d.of(n.reverseChangeSet, t.doc.length).compose(d.of(r, a.length)), m = d.of(r, a.length).invert(a);
  return e.dispatch({
    changes: u,
    effects: S.of({
      index: c,
      reverseChangeSet: m,
      changeSpecs: o
    }),
    annotations: [
      // Tell upstream integrations to ignore this
      // change.
      g.of(null),
      // Tell ourselves not to request a completion
      // because of this change.
      f.of(null),
      // Don't add this to history.
      l.addToHistory.of(!1)
    ]
  }), !0;
}, "nextSuggestionCommand");
function v(e) {
  const t = e.state.field(i);
  return t && e.dispatch({
    changes: t.reverseChangeSet,
    effects: C.of(null),
    annotations: [
      // Tell upstream integrations to ignore this
      // change. This was never really in the document
      // in the first place - we were just showing ghost text.
      g.of(null),
      f.of(null),
      l.addToHistory.of(!1)
    ]
  }), !1;
}
s(v, "rejectSuggestionCommand");
function b(e, t) {
  return e.state.field(i) ? t === "Tab" ? T(e) : v(e) : !1;
}
s(b, "sameKeyCommand");
const j = /* @__PURE__ */ s((e) => (y(e), !0), "startCompletion");
export {
  T as acceptSuggestionCommand,
  R as nextSuggestionCommand,
  v as rejectSuggestionCommand,
  b as sameKeyCommand,
  j as startCompletion
};
