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