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

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