"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var LinkPlugin_exports = {};
__export(LinkPlugin_exports, {
  LinkPlugin: () => LinkPlugin,
  withLink: () => withLink
});
module.exports = __toCommonJS(LinkPlugin_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_css = require("@emotion/css");
var import_controls = require("@makeswift/controls");
var import_link = require("../../controls/link");
var import_use_style = require("../../runtimes/react/use-style");
var import_Link = require("../../components/shared/Link");
var import_plugin = require("../../controls/rich-text-v2/plugin");
var import_onChange = require("./onChange");
var import_getValue = require("./getValue");
const withLink = (editor) => {
  const { isInline } = editor;
  editor.isInline = (entry) => {
    return import_controls.Slate.isInline(entry) && isInline(entry);
  };
  return editor;
};
function InlinePluginComponent({
  element,
  attributes,
  children,
  renderElement
}) {
  const linkStyle = (0, import_use_style.useStyle)({ textDecoration: "none" });
  switch (element.type) {
    case import_controls.Slate.InlineType.Link:
      return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
        import_Link.Link,
        {
          ...attributes,
          link: element.link ?? void 0,
          className: (0, import_css.cx)(linkStyle, element.className),
          children: renderElement({
            element,
            attributes,
            children
          })
        }
      );
    default:
      return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: renderElement({
        element,
        attributes,
        children
      }) });
  }
}
function LinkPlugin() {
  return (0, import_plugin.Plugin)({
    control: {
      definition: (0, import_link.Link)({
        label: "On Click"
      }),
      onChange: import_onChange.onChange,
      getValue: import_getValue.getValue,
      getElementValue: (element) => {
        return import_controls.Slate.isLink(element) ? element.link : void 0;
      }
    },
    withPlugin: withLink,
    renderElement: (renderElement) => (props) => {
      return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(InlinePluginComponent, { ...props, renderElement });
    }
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  LinkPlugin,
  withLink
});
//# sourceMappingURL=index.js.map