import {
  ButtonUniDriver,
  InputUniDriver,
  SegmentedToggleUniDriver,
  ToggleSwitchUniDriver
} from "@wix/design-system/dist/testkit/unidriver.js";
import { createFigureTestkit } from "./../plugin-figure/testkit.js";
import { RicosPluginToolbarNames } from "./../ricos-types/index.js";
import {
  PLUGIN_TOOLBAR_DELETE_BUTTON,
  PLUGIN_TOOLBAR_REPLACE_BUTTON,
  PLUGIN_TOOLBAR_SETTINGS_BUTTON,
  SPOILER_CONTAINER
} from "./../_shared/data-hooks.js";
import { dataHook } from "./../wix-rich-content-common/index.js";
import {
  EMBED_TAB_SUBMIT_BUTTON,
  EMBED_TAB_URL_INPUT,
  INSERT_VIDEO_BUTTON,
  INSERT_VIDEO_MODAL,
  INSERT_VIDEO_MODAL_SOURCE_TOGGLE,
  SETTINGS_DISABLE_DOWNLOAD_TOGGLE,
  SETTINGS_SPOILER_TOGGLE,
  UPLOAD_TAB_UPLOAD_BUTTON,
  VIDEO_ROOT
} from "./data-hooks.js";
import { toolbarsToAddIn } from "./get-add-buttons.js";
const createVideoTestkit = (getBase) => {
  const getVideo = async (index, options) => {
    const video = await getBase().getAll(dataHook(VIDEO_ROOT), options);
    return video.at(index);
  };
  const getVideoModalBase = async () => {
    const modal = await getBase().get(dataHook(INSERT_VIDEO_MODAL));
    return modal;
  };
  const getPreview = async (index) => {
    const video = await getVideo(index);
    return video.get(".react-player__preview");
  };
  const hasPreview = async (index) => {
    try {
      await getPreview(index);
      return true;
    } catch {
      return false;
    }
  };
  return {
    content: {
      atIndex: (index) => {
        return {
          exists: async (options) => {
            try {
              const video = await getVideo(index, options);
              return video.exists();
            } catch {
              return false;
            }
          },
          click: async () => {
            if (await hasPreview(index)) {
              const preview = await getPreview(index);
              await preview.click();
              return;
            }
            const video = await getVideo(index);
            await video.click();
          },
          hasSpoiler: async () => {
            try {
              const spoiler = await getBase().get(dataHook(SPOILER_CONTAINER));
              return spoiler.exists();
            } catch {
              return false;
            }
          },
          waitForPlayer: async () => {
            const player = await getVideo(index);
            return player.wait();
          },
          hasVideo: async () => {
            try {
              const player = await getVideo(index);
              await player.get("video");
              return true;
            } catch {
              return false;
            }
          },
          hasPreview: () => hasPreview(index),
          getNativeElement: async () => {
            const video = await getVideo(index);
            return video.getNative();
          },
          ...createFigureTestkit(getBase, index)
        };
      }
    },
    toolbars: {
      createAddButtonToolbars: (getAddButtonToolbarBase) => ({
        click: async () => {
          const button = await getAddButtonToolbarBase().get(dataHook(INSERT_VIDEO_BUTTON));
          await button.click();
        },
        toolbarsToAddIn
      }),
      createPluginToolbar: (getPluginToolbarBase) => ({
        openReplaceModal: async () => {
          await (await getPluginToolbarBase(RicosPluginToolbarNames.VIDEO).get(
            dataHook(PLUGIN_TOOLBAR_REPLACE_BUTTON)
          )).click();
        },
        openSettingsModal: async () => {
          await (await getPluginToolbarBase(RicosPluginToolbarNames.VIDEO).get(
            dataHook(PLUGIN_TOOLBAR_SETTINGS_BUTTON)
          )).click();
        },
        settingsButtonExists: async () => {
          return getPluginToolbarBase(RicosPluginToolbarNames.VIDEO).$(dataHook(PLUGIN_TOOLBAR_SETTINGS_BUTTON)).exists();
        },
        clickDelete: async () => {
          await (await getPluginToolbarBase(RicosPluginToolbarNames.VIDEO).get(
            dataHook(PLUGIN_TOOLBAR_DELETE_BUTTON)
          )).click();
        },
        exists: async () => {
          try {
            return getPluginToolbarBase(RicosPluginToolbarNames.VIDEO).exists();
          } catch {
            return false;
          }
        }
      })
    },
    insertModal: {
      sourceSegmentedToggle: SegmentedToggleUniDriver(
        getBase().$(dataHook(INSERT_VIDEO_MODAL_SOURCE_TOGGLE)),
        getBase()
      ),
      embedSection: {
        urlInput: InputUniDriver(getBase().$(dataHook(EMBED_TAB_URL_INPUT)), getBase()),
        submitButton: ButtonUniDriver(getBase().$(dataHook(EMBED_TAB_SUBMIT_BUTTON)), getBase())
      },
      uploadSection: {
        uploadButton: ButtonUniDriver(getBase().$(dataHook(UPLOAD_TAB_UPLOAD_BUTTON)), getBase())
      },
      waitForElement: async () => {
        const element = await getVideoModalBase();
        await element.wait();
      }
    },
    settings: {
      disableDownloadToggle: ToggleSwitchUniDriver(
        getBase().$(dataHook(SETTINGS_DISABLE_DOWNLOAD_TOGGLE)),
        getBase()
      ),
      spoilerToggle: ToggleSwitchUniDriver(
        getBase().$(dataHook(SETTINGS_SPOILER_TOGGLE)),
        getBase()
      )
    }
  };
};
export {
  createVideoTestkit
};
//# sourceMappingURL=testkit.js.map
