import { __exports as a } from "./index-useInteractionManager2.js";
import { __require as q } from "./index-LexicalLink2.js";
import { __require as U } from "./index-LexicalUtils.js";
import { __require as h } from "./index-Lexical.js";
import A from "react";
import { __require as G } from "./index-getSelectedNode.js";
var N;
function T() {
  if (N) return a;
  N = 1, Object.defineProperty(a, "__esModule", { value: !0 }), a.useInteractionManager = void 0;
  const l = q(), E = U(), o = h(), r = A, k = G();
  function v(R) {
    const { editor: e, isLink: d, anchorElem: m, setIsLink: L } = R, [S, c] = (0, r.useState)(""), [I, g] = (0, r.useState)(), [C, M] = (0, r.useState)(null), i = (0, r.useCallback)(() => {
      var t, n;
      const u = (0, o.$getSelection)();
      if ((0, o.$isRangeSelection)(u)) {
        const s = (0, k.getSelectedNode)(u), p = (0, E.$findMatchingParent)(s, l.$isLinkNode);
        p ? c(p.getURL()) : (0, l.$isLinkNode)(s) ? c(s.getURL()) : c("");
      }
      const _ = window.getSelection(), O = document.activeElement, f = e.getRootElement();
      if (u !== null && _ !== null && f !== null && f.contains(_.anchorNode) && e.isEditable()) {
        const s = (n = (t = _.focusNode) === null || t === void 0 ? void 0 : t.parentElement) === null || n === void 0 ? void 0 : n.getBoundingClientRect();
        s && g(s), M(u);
      } else O || (f !== null && g(void 0), M(null), c(""));
      return !0;
    }, [m, e]);
    return (0, r.useEffect)(() => {
      const t = m.parentElement, n = () => {
        e.getEditorState().read(() => {
          i();
        });
      };
      return window.addEventListener("resize", n), t && t.addEventListener("scroll", n), () => {
        window.removeEventListener("resize", n), t && t.removeEventListener("scroll", n);
      };
    }, [m.parentElement, e, i]), (0, r.useEffect)(() => (0, E.mergeRegister)(e.registerUpdateListener(({ editorState: t }) => {
      t.read(() => {
        i();
      });
    }), e.registerCommand(o.SELECTION_CHANGE_COMMAND, () => (i(), !0), o.COMMAND_PRIORITY_LOW), e.registerCommand(o.KEY_ESCAPE_COMMAND, () => d ? (L(!1), !0) : !1, o.COMMAND_PRIORITY_HIGH)), [e, i, L, d]), (0, r.useEffect)(() => {
      e.getEditorState().read(() => {
        i();
      });
    }, [e, i]), {
      currentNodeIsLink: d,
      linkNodeRect: I,
      linkUrl: S,
      dispatchLinkSubmission: ({ url: t }) => {
        C !== null && e.dispatchCommand(l.TOGGLE_LINK_COMMAND, t);
      },
      dispatchLinkRemoval: () => {
        e.dispatchCommand(l.TOGGLE_LINK_COMMAND, null);
      }
    };
  }
  return a.useInteractionManager = v, a;
}
export {
  T as __require
};
