import { Reels, ReelsSmall } from "@wix/wix-ui-icons-common";
import { TIPTAP_GIF_TYPE } from "./../ricos-content/index.js";
import {
  Node_Type,
  RicosPluginToolbarNames,
  quickActionsModalSections
} from "./../ricos-types/index.js";
import { posToDOMRect } from "./../tiptap/index.js";
import { pluginFigure } from "../plugin-figure/editor.js";
import { DEFAULT_CONFIGS, gifModals } from "./constants.js";
import { gifConverter } from "./converter/gif-converter.js";
import { getAddButtons } from "./get-add-buttons.js";
import { getToolbarButtons } from "./get-toolbar-buttons.js";
import { GiphyInsertModal } from "./modals/insert-modal.js";
import { tiptapExtensions } from "./tiptap/tiptap.js";
import { GIPHY_TYPE } from "./types.js";
const pluginGiphy = (config) => {
  const pluginConfig = { type: "giphy", ...DEFAULT_CONFIGS.editor, ...config };
  return {
    config: pluginConfig,
    pmMarkConverters: [],
    pmNodeConverters: [gifConverter],
    type: GIPHY_TYPE,
    tiptapExtensions,
    getAddButtons: (config2, services) => getAddButtons(config2, services),
    toolbar: {
      names: [RicosPluginToolbarNames.GIF],
      getButtons: (config2, services) => getToolbarButtons(config2, services),
      resolveReferenceElement: (tiptapEditor) => {
        const startNodePos = tiptapEditor.state.selection.$from;
        if (startNodePos.nodeAfter?.type.name !== TIPTAP_GIF_TYPE) {
          return null;
        }
        return tiptapEditor.view.nodeDOM(startNodePos.pos - 1);
      }
    },
    getQuickActions: ({ config: config2, pluginServices }) => {
      const isMobile = pluginServices?.context.isMobile;
      return [
        {
          id: Node_Type.GIF,
          title: "GIF",
          icon: isMobile ? Reels : ReelsSmall,
          section: quickActionsModalSections.Media,
          tags: ["animation", "motion", "clip", "short", "funny", "meme", "loop"],
          command: ({ modalService, editor, referenceElement }) => {
            modalService.togglePluginPanel({
              id: gifModals.insert,
              Component: GiphyInsertModal,
              componentProps: {
                modalId: gifModals.insert,
                getGiphyUrl: config2?.getGiphyUrl
              },
              isMobile,
              positioning: {
                referenceElement: referenceElement ?? {
                  getBoundingClientRect: () => posToDOMRect(
                    editor.view,
                    editor.view.state.selection.from,
                    editor.view.state.selection.to
                  )
                },
                placement: "bottom-start"
              }
            });
          }
        }
      ];
    },
    dependencies: [pluginFigure]
  };
};
export {
  pluginGiphy
};
//# sourceMappingURL=editor.js.map

import { injectCss } from "./viewer-styles-inject.js";
injectCss();
