import { VideoCamera, VideoCameraSmall, Youtube, YoutubeSmall } from "@wix/wix-ui-icons-common";
import { TIPTAP_VIDEO_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 {
  RICOS_DEFAULTS,
  VIDEO_INSERT_VIDEO_MODAL_ID,
  VIDEO_INSERT_YOUTUBE_MODAL_ID
} from "./constants.js";
import { videoConverter } from "./converter/video-converter.js";
import { DEFAULT_CONFIGS } 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 { VIDEO_TYPE, videoButtonsTypes } from "./types.js";
const pluginVideo = (config) => {
  const pluginConfig = {
    type: "video",
    ...DEFAULT_CONFIGS.editor,
    ...config
  };
  return {
    config: pluginConfig,
    type: VIDEO_TYPE,
    pmMarkConverters: [],
    pmNodeConverters: [videoConverter],
    tiptapExtensions,
    getAddButtons,
    toolbar: {
      names: [RicosPluginToolbarNames.VIDEO],
      getButtons: (config2, services) => getToolbarButtons(config2, services),
      resolveReferenceElement: (tiptapEditor) => {
        const startNodePos = tiptapEditor.state.selection.$from;
        if (startNodePos.nodeAfter?.type.name !== TIPTAP_VIDEO_TYPE) {
          return null;
        }
        return tiptapEditor.view.nodeDOM(startNodePos.pos - 1);
      }
    },
    getQuickActions: ({ config: config2, pluginServices }) => {
      const { disableDownloadDefault, getVideoUrl } = config2 || {};
      const modalBaseProps = {
        disableDownloadDefault,
        getVideoUrl
      };
      const isMobile = pluginServices?.context.isMobile;
      return [
        {
          id: `${Node_Type.VIDEO}.video`,
          title: "QuickActionsPlugin_ActionTitle_Video",
          icon: isMobile ? VideoCamera : VideoCameraSmall,
          section: quickActionsModalSections.Media,
          tags: ["clip", "movie", "film", "record", "stream"],
          command: ({ editor, modalService, referenceElement }) => {
            modalService.togglePluginPanel({
              id: VIDEO_INSERT_VIDEO_MODAL_ID,
              Component: InsertModal,
              componentProps: {
                componentData: { ...RICOS_DEFAULTS },
                modalId: VIDEO_INSERT_VIDEO_MODAL_ID,
                ...modalBaseProps
              },
              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"
            });
          }
        },
        {
          id: `${Node_Type.VIDEO}.youTube`,
          title: "QuickActionsPlugin_ActionTitle_YoutubeVideo",
          icon: isMobile ? Youtube : YoutubeSmall,
          section: quickActionsModalSections.Embed,
          tags: ["clip", "movie", "film", "record", "stream", "link", "content", "youtube"],
          command: ({ editor, modalService, referenceElement }) => {
            modalService.togglePluginPanel({
              id: VIDEO_INSERT_YOUTUBE_MODAL_ID,
              Component: InsertModal,
              componentProps: {
                componentData: { ...RICOS_DEFAULTS, type: videoButtonsTypes.youTube },
                modalId: VIDEO_INSERT_YOUTUBE_MODAL_ID,
                ...modalBaseProps
              },
              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"
            });
          }
        }
      ];
    },
    dependencies: [pluginFigure]
  };
};
export {
  pluginVideo
};
//# sourceMappingURL=editor.js.map

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