import { Fragment, jsx } from "react/jsx-runtime";
import { cx } from "@emotion/css";
import { Slate } from "@makeswift/controls";
import { Link } from "../../controls/link";
import { useStyle } from "../../runtimes/react/use-style";
import { Link as LinkComponent } from "../../components/shared/Link";
import { Plugin } from "../../controls/rich-text-v2/plugin";
import { onChange } from "./onChange";
import { getValue } from "./getValue";
const withLink = (editor) => {
  const { isInline } = editor;
  editor.isInline = (entry) => {
    return Slate.isInline(entry) && isInline(entry);
  };
  return editor;
};
function InlinePluginComponent({
  element,
  attributes,
  children,
  renderElement
}) {
  const linkStyle = useStyle({ textDecoration: "none" });
  switch (element.type) {
    case Slate.InlineType.Link:
      return /* @__PURE__ */ jsx(
        LinkComponent,
        {
          ...attributes,
          link: element.link ?? void 0,
          className: cx(linkStyle, element.className),
          children: renderElement({
            element,
            attributes,
            children
          })
        }
      );
    default:
      return /* @__PURE__ */ jsx(Fragment, { children: renderElement({
        element,
        attributes,
        children
      }) });
  }
}
function LinkPlugin() {
  return Plugin({
    control: {
      definition: Link({
        label: "On Click"
      }),
      onChange,
      getValue,
      getElementValue: (element) => {
        return Slate.isLink(element) ? element.link : void 0;
      }
    },
    withPlugin: withLink,
    renderElement: (renderElement) => (props) => {
      return /* @__PURE__ */ jsx(InlinePluginComponent, { ...props, renderElement });
    }
  });
}
export {
  LinkPlugin,
  withLink
};
//# sourceMappingURL=index.js.map