var s = Object.defineProperty;
var r = (t, e) => s(t, "name", { value: e, configurable: !0 });
import { CompletionContext as f, completionStatus as m } from "../../../../../@codemirror_autocomplete@6.18.6/node_modules/@codemirror/autocomplete/dist/index.js";
import { EditorView as u } from "../../../../../@codemirror_view@6.36.4/node_modules/@codemirror/view/dist/index.js";
import { acceptSuggestion as c, clearSuggestion as a } from "./effects.js";
import { completionDecoration as l } from "./completionDecoration.js";
import { copilotEvent as p } from "./annotations.js";
import { codeiumConfig as g } from "./config.js";
import { requestCompletion as w } from "./requestCompletion.js";
function C(t) {
  return t.docChanged && !t.transactions.some((e) => e.effects.some((o) => o.is(c) || o.is(a)));
}
r(C, "shouldRequestCompletion");
function h(t) {
  if (!t.view.hasFocus || t.state.field(l) || m(t.state) === "active")
    return !0;
  for (const e of t.transactions)
    if (e.annotation(p) !== void 0)
      return !0;
}
r(h, "shouldIgnoreUpdate");
function D() {
  let t = null, e = 0;
  return u.updateListener.of((o) => {
    const i = o.view.state.facet(g);
    if (!i.alwaysOn || !C(o) || (t && clearTimeout(t), h(o)))
      return;
    const n = o.state.selection.main.head;
    i.shouldComplete && !i.shouldComplete(new f(o.view.state, n, !1)) || (t = setTimeout(async () => {
      n === e && await w(o.view, e);
    }, i.timeout), e = n);
  });
}
r(D, "completionRequester");
export {
  D as completionRequester
};
