import { __exports as o } from "./index-_virtual24.js";
import { __require as I } from "./index-LexicalLink2.js";
import { __require as q } from "./index-LexicalUtils.js";
import { __require as C } from "./index-Lexical.js";
import $ from "react";
import { __require as R } from "./index-getSelectedNode.js";
import { __require as S } from "./index-useInteractionManager.js";
var f;
function v() {
  if (f) return o;
  f = 1, Object.defineProperty(o, "__esModule", { value: !0 }), o.useHyperlinkEditor = void 0;
  const s = I(), a = q(), e = C(), u = $, l = R(), k = S();
  function m(p) {
    const { editor: i, anchorElem: L, canEditAutoLinks: g = !0 } = p, [M, N] = (0, u.useState)(i), [E, d] = (0, u.useState)(!1);
    return (0, u.useEffect)(() => {
      function _() {
        const t = (0, e.$getSelection)();
        if ((0, e.$isRangeSelection)(t)) {
          const r = (0, l.getSelectedNode)(t), c = (0, a.$findMatchingParent)(r, s.$isLinkNode), n = (0, a.$findMatchingParent)(r, s.$isAutoLinkNode);
          d(g ? c !== null || n !== null : c !== null && n === null);
        }
      }
      return (0, a.mergeRegister)(i.registerUpdateListener(({ editorState: t }) => {
        t.read(() => {
          _();
        });
      }), i.registerCommand(e.SELECTION_CHANGE_COMMAND, (t, r) => (_(), N(r), !1), e.COMMAND_PRIORITY_CRITICAL), i.registerCommand(e.CLICK_COMMAND, (t) => {
        const r = (0, e.$getSelection)();
        if ((0, e.$isRangeSelection)(r)) {
          const c = (0, l.getSelectedNode)(r), n = (0, a.$findMatchingParent)(c, s.$isLinkNode);
          if ((0, s.$isLinkNode)(n) && (t.metaKey || t.ctrlKey))
            return window.open(n.getURL(), "_blank"), !0;
        }
        return !1;
      }, e.COMMAND_PRIORITY_LOW));
    }, [i]), (0, k.useInteractionManager)({
      editor: M,
      isLink: E,
      anchorElem: L,
      setIsLink: d
    });
  }
  return o.useHyperlinkEditor = m, o;
}
export {
  v as __require
};
