import { __exports as l } from "./index-LexicalLinkPlugin.dev2.js";
import { __require as g } from "./index-LexicalLink2.js";
import { __require as d } from "./index-LexicalComposerContext2.js";
import { __require as x } from "./index-LexicalUtils.js";
import { __require as C } from "./index-Lexical.js";
import p from "react";
var a;
function P() {
  if (a) return l;
  a = 1;
  var r = g(), f = d(), c = x(), i = C(), L = p;
  function _({
    validateUrl: t
  }) {
    const [n] = f.useLexicalComposerContext();
    return L.useEffect(() => {
      if (!n.hasNodes([r.LinkNode]))
        throw new Error("LinkPlugin: LinkNode not registered on editor");
      return c.mergeRegister(n.registerCommand(r.TOGGLE_LINK_COMMAND, (e) => {
        if (e === null)
          return r.toggleLink(e), !0;
        if (typeof e == "string")
          return t === void 0 || t(e) ? (r.toggleLink(e), !0) : !1;
        {
          const {
            url: o,
            target: u,
            rel: s,
            title: m
          } = e;
          return r.toggleLink(o, {
            rel: s,
            target: u,
            title: m
          }), !0;
        }
      }, i.COMMAND_PRIORITY_LOW), t !== void 0 ? n.registerCommand(i.PASTE_COMMAND, (e) => {
        const o = i.$getSelection();
        if (!i.$isRangeSelection(o) || o.isCollapsed() || !(e instanceof ClipboardEvent) || e.clipboardData == null)
          return !1;
        const u = e.clipboardData.getData("text");
        return t(u) ? o.getNodes().some((s) => i.$isElementNode(s)) ? !1 : (n.dispatchCommand(r.TOGGLE_LINK_COMMAND, u), e.preventDefault(), !0) : !1;
      }, i.COMMAND_PRIORITY_LOW) : () => {
      });
    }, [n, t]), null;
  }
  return l.LinkPlugin = _, l;
}
export {
  P as __require
};
