"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, {
  pluginAudio: () => pluginAudio
});
module.exports = __toCommonJS(editor_exports);
var import_wix_ui_icons_common = require("@wix/wix-ui-icons-common");
var import_ricos_types = require("./../ricos-types/index.js");
var import_tiptap = require("./../tiptap/index.js");
var import_consts = require("./consts.js");
var import_audio_converter = require("./converters/audio-converter.js");
var import_defaults = require("./defaults.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 pluginAudio = (config = {}) => {
  return {
    config: { ...import_defaults.DEFAULT_CONFIGS.editor, ...config, type: "audio" },
    type: import_types.AUDIO_TYPE,
    tiptapExtensions: import_tiptap2.tiptapExtensions,
    pmMarkConverters: [],
    pmNodeConverters: [import_audio_converter.audioConverter],
    toolbar: {
      names: [import_ricos_types.RicosPluginToolbarNames.AUDIO],
      getButtons: (config2, services) => (0, import_get_toolbar_buttons.getToolbarButtons)(config2, services)
    },
    getAddButtons: (config2, services) => (0, import_get_add_buttons.getAddButtons)(config2, services),
    getQuickActions: ({ config: config2, pluginServices }) => {
      const { disableDownload = true, exposeButtons = ["audio"] } = config2 || {};
      const isMobile = pluginServices.context.isMobile;
      const actions = [];
      if (exposeButtons.includes(import_types.audioButtonsTypes.audio)) {
        actions.push({
          id: `${import_ricos_types.Node_Type.AUDIO}.audio`,
          title: "QuickActionsPlugin_ActionTitle_AudioFile",
          icon: isMobile ? import_wix_ui_icons_common.Sound : import_wix_ui_icons_common.SoundSmall,
          section: import_ricos_types.quickActionsModalSections.Media,
          tags: ["music", "sound", "podcast", "voice", "recording", "song", "clip", "track"],
          command: ({ modalService, editor, referenceElement }) => {
            modalService.togglePluginPanel({
              id: import_consts.AUDIO_INSERT_AUDIO_MODAL_ID,
              Component: import_insert_modal.InsertModal,
              componentProps: {
                componentData: { ...import_defaults.RICOS_DEFAULTS, disableDownload },
                modalId: import_consts.AUDIO_INSERT_AUDIO_MODAL_ID
              },
              isMobile,
              positioning: {
                referenceElement: referenceElement ?? {
                  getBoundingClientRect: () => (0, import_tiptap.posToDOMRect)(
                    editor.view,
                    editor.view.state.selection.from,
                    editor.view.state.selection.to
                  )
                },
                placement: isMobile ? "bottom" : "bottom-start"
              },
              mobileLayout: "drawer"
            });
          }
        });
      }
      if (exposeButtons.includes(import_types.audioButtonsTypes.soundCloud)) {
        actions.push({
          id: `${import_ricos_types.Node_Type.AUDIO}.soundCloud`,
          title: "QuickActionsPlugin_ActionTitle_SoundCloud",
          icon: import_wix_ui_icons_common.SoundCloudSmall,
          section: import_ricos_types.quickActionsModalSections.Embed,
          tags: [
            "music",
            "sound",
            "podcast",
            "voice",
            "recording",
            "song",
            "clip",
            "link",
            "streaming",
            "track",
            "soundcloud"
          ],
          command: ({ modalService, editor, referenceElement }) => {
            modalService.togglePluginPanel({
              id: import_consts.AUDIO_INSERT_SOUNDCLOUD_MODAL_ID,
              Component: import_insert_modal.InsertModal,
              componentProps: {
                componentData: { ...import_defaults.RICOS_DEFAULTS },
                modalId: import_consts.AUDIO_INSERT_SOUNDCLOUD_MODAL_ID,
                embedType: true
              },
              isMobile,
              positioning: {
                referenceElement: referenceElement ?? {
                  getBoundingClientRect: () => (0, import_tiptap.posToDOMRect)(
                    editor.view,
                    editor.view.state.selection.from,
                    editor.view.state.selection.to
                  )
                },
                placement: isMobile ? "bottom" : "bottom-start"
              },
              mobileLayout: "drawer"
            });
          }
        });
      }
      if (exposeButtons.includes(import_types.audioButtonsTypes.spotify)) {
        actions.push({
          id: `${import_ricos_types.Node_Type.AUDIO}.spotify`,
          title: "QuickActionsPlugin_ActionTitle_SpotifyTrack",
          icon: import_wix_ui_icons_common.SpotifySmall,
          section: import_ricos_types.quickActionsModalSections.Embed,
          tags: [
            "music",
            "sound",
            "podcast",
            "voice",
            "recording",
            "song",
            "clip",
            "link",
            "streaming",
            "track",
            "playlist",
            "spotify"
          ],
          command: ({ modalService, editor, referenceElement }) => {
            modalService.togglePluginPanel({
              id: import_consts.AUDIO_INSERT_SPOTIFY_MODAL_ID,
              Component: import_insert_modal.InsertModal,
              componentProps: {
                componentData: { ...import_defaults.RICOS_DEFAULTS },
                modalId: import_consts.AUDIO_INSERT_SPOTIFY_MODAL_ID,
                embedType: true
              },
              isMobile,
              positioning: {
                referenceElement: referenceElement ?? {
                  getBoundingClientRect: () => (0, import_tiptap.posToDOMRect)(
                    editor.view,
                    editor.view.state.selection.from,
                    editor.view.state.selection.to
                  )
                },
                placement: isMobile ? "bottom" : "bottom-start"
              },
              mobileLayout: "drawer"
            });
          }
        });
      }
      return actions;
    }
  };
};
//# sourceMappingURL=editor.js.map
