import {
  InputAreaUniDriver,
  InputUniDriver,
  NumberInputUniDriver,
  SegmentedToggleUniDriver,
  SliderUniDriver,
  ToggleSwitchUniDriver
} from "@wix/design-system/dist/testkit/unidriver.js";
import { RicosPluginToolbarNames } from "./../ricos-types/index.js";
import { PLUGIN_TOOLBAR_DELETE_BUTTON } from "./../_shared/data-hooks.js";
import { createPromptInputAreaUniDriver } from "./../_shared/prompt-input-area/prompt-input-area-unidriver.js";
import { dataHook } from "./../wix-rich-content-common/index.js";
import {
  createFooterActionsUnidriver
} from "./../ui-components/testkit.js";
import {
  AI_WIDGET_HTML_VIEWER,
  EDIT_PANEL,
  EDIT_PANEL_HTML_INPUT,
  EDIT_PANEL_SEGMENTED_TOGGLE,
  EDIT_PANEL_URL_INPUT,
  HTML_DIMENSIONS_INPUT,
  HTML_DIMENSIONS_SLIDER,
  HTML_HEIGHT_AUTOHEIGHT_TOGGLE,
  HTML_SLIDER_MODAL,
  HTML_VIEWER_ROOT,
  IFRAME_COMPONENT,
  INSERT_ADSENSE_BUTTON,
  INSERT_HTML_BUTTON,
  PLUGIN_TOOLBAR_CONTAINER_HEIGHT_BUTTON,
  PLUGIN_TOOLBAR_EDIT_HTML_BUTTON,
  PROMPT_INPUT_AREA
} from "./data-hooks.js";
import { toolbarsToAddIn } from "./get-add-buttons.js";
const createHtmlTestkit = (getBase) => {
  const getHtml = async (index, options) => {
    const html = await getBase().getAll(dataHook(HTML_VIEWER_ROOT), options);
    return html.at(index);
  };
  const getIframe = async (index) => {
    const iframe = await getBase().getAll(dataHook(IFRAME_COMPONENT));
    return iframe.at(index);
  };
  const getAiWidget = async () => {
    return getBase().$(dataHook(AI_WIDGET_HTML_VIEWER));
  };
  return {
    content: {
      atIndex: (index) => {
        return {
          exists: async (options) => {
            try {
              const html = await getHtml(index, options);
              return html.exists();
            } catch {
              return false;
            }
          },
          getSrc: async () => (await getIframe(index)).attr("src"),
          getIframeNativeElement: async () => {
            const iframe = await getIframe(index);
            return iframe.getNative();
          },
          click: async () => {
            const html = await getHtml(index);
            await html.click();
          }
        };
      }
    },
    aiWidget: {
      promptInput: createPromptInputAreaUniDriver(getBase, PROMPT_INPUT_AREA),
      exists: async () => {
        try {
          return (await getAiWidget()).exists();
        } catch {
          return false;
        }
      },
      click: async () => {
        const widget = await getAiWidget();
        await widget.click();
      }
    },
    editHeightModal: {
      autoHeightToggle: ToggleSwitchUniDriver(
        getBase().$(dataHook(HTML_HEIGHT_AUTOHEIGHT_TOGGLE)),
        getBase()
      ),
      slider: SliderUniDriver(getBase().$(dataHook(HTML_DIMENSIONS_SLIDER)), getBase()),
      heightInput: NumberInputUniDriver(getBase().$(dataHook(HTML_DIMENSIONS_INPUT)), getBase()),
      waitForElement: async () => {
        const el = await getBase().get(dataHook(HTML_SLIDER_MODAL));
        await el.wait();
      }
    },
    editHtmlModal: {
      typeSegmentedToggle: SegmentedToggleUniDriver(
        getBase().$(dataHook(EDIT_PANEL_SEGMENTED_TOGGLE)),
        getBase()
      ),
      htmlInputArea: InputAreaUniDriver(getBase().$(dataHook(EDIT_PANEL_HTML_INPUT)), getBase()),
      urlInput: InputUniDriver(getBase().$(dataHook(EDIT_PANEL_URL_INPUT)), getBase()),
      waitForElement: async () => {
        const el = await getBase().get(dataHook(EDIT_PANEL));
        await el.wait();
      },
      ...createFooterActionsUnidriver(getBase)
    },
    toolbars: {
      createAddButtonToolbars: (getAddButtonBase) => ({
        clickHtml: async () => {
          const htmlButton = await getAddButtonBase().get(dataHook(INSERT_HTML_BUTTON));
          await htmlButton.click();
        },
        clickAdsense: async () => {
          const adsenseButton = await getAddButtonBase().get(dataHook(INSERT_ADSENSE_BUTTON));
          await adsenseButton.click();
        },
        toolbarsToAddIn
      }),
      createPluginToolbar: (getPluginToolbarBase) => {
        return {
          exists: async () => {
            try {
              return getPluginToolbarBase(RicosPluginToolbarNames.HTML).exists();
            } catch {
              return false;
            }
          },
          clickEditHtml: async () => {
            const editHTMLButton = await getPluginToolbarBase(RicosPluginToolbarNames.HTML).get(
              dataHook(PLUGIN_TOOLBAR_EDIT_HTML_BUTTON)
            );
            await editHTMLButton.click();
          },
          clickDelete: async () => {
            const deleteButton = await getPluginToolbarBase(RicosPluginToolbarNames.HTML).get(
              dataHook(PLUGIN_TOOLBAR_DELETE_BUTTON)
            );
            await deleteButton.click();
          },
          clickEditHeight: async () => {
            const heightButton = await getPluginToolbarBase(RicosPluginToolbarNames.HTML).get(
              dataHook(PLUGIN_TOOLBAR_CONTAINER_HEIGHT_BUTTON)
            );
            await heightButton.click();
          }
        };
      }
    }
  };
};
export {
  createHtmlTestkit
};
//# sourceMappingURL=testkit.js.map
