import { Fragment, jsx } from "react/jsx-runtime";
import { unstable_IconRadioGroup, Slate } from "@makeswift/controls";
import { Plugin } from "../../controls/rich-text-v2/plugin";
import { supportedInlineOptions, isSupportedInlineNode } from "./types";
import { onChange } from "./onChange";
import { getValue } from "./getValue";
const withInline = (editor) => {
  const { isInline } = editor;
  editor.isInline = (entry) => {
    return Slate.isInline(entry) && isInline(entry);
  };
  return editor;
};
function InlinePlugin() {
  return Plugin({
    control: {
      definition: unstable_IconRadioGroup({
        label: "Inline",
        options: supportedInlineOptions
      }),
      onChange,
      getValue,
      getElementValue: (element) => isSupportedInlineNode(element) ? element.type : void 0
    },
    withPlugin: withInline,
    renderElement: (renderElement) => (props) => {
      return /* @__PURE__ */ jsx(InlinePluginComponent, { ...props, renderElement });
    }
  });
}
function InlinePluginComponent({
  renderElement,
  ...props
}) {
  switch (props.element.type) {
    case Slate.InlineType.Code:
      return /* @__PURE__ */ jsx("code", { ...props.attributes, children: renderElement(props) });
    case Slate.InlineType.SuperScript:
      return /* @__PURE__ */ jsx("sup", { ...props.attributes, children: renderElement(props) });
    case Slate.InlineType.SubScript:
      return /* @__PURE__ */ jsx("sub", { ...props.attributes, children: renderElement(props) });
    default:
      return /* @__PURE__ */ jsx(Fragment, { children: renderElement(props) });
  }
}
export {
  InlinePlugin,
  withInline
};
//# sourceMappingURL=index.js.map