import {
  ButtonUniDriver,
  CloseButtonUniDriver,
  IconButtonUniDriver,
  InputAreaUniDriver,
  ListItemActionUniDriver,
  MessageModalLayoutUniDriver,
  PopoverMenuUniDriver,
  PopoverUniDriver,
  SidePanelUniDriver,
  TextButtonUniDriver
} from "@wix/design-system/dist/testkit/unidriver.js";
import {
  createDropdownModalUniDriver
} from "./../_shared/dropdown-modal/dropdown-modal-uni-driver.js";
import { dataHook } from "./../wix-rich-content-common/index.js";
import {
  AI_EXPORTS_ALT_TEXT_GENERATE_BUTTON,
  AI_EXPORTS_ALT_TEXT_INPUT_AREA,
  AI_EXPORTS_CAPTION_TRIGGER_BUTTON,
  AI_FLOW_SELECTION_POPOVER,
  AI_IMAGE_MODAL_ACTION_INSERT,
  AI_IMAGE_MODAL_ACTION_INSERT_ABOVE,
  AI_IMAGE_MODAL_ACTION_INSERT_BELOW,
  AI_IMAGE_MODAL_CANCEL_BUTTON,
  AI_IMAGE_MODAL_ERROR_CANCEL_BUTTON,
  AI_IMAGE_MODAL_ERROR_RETRY_BUTTON,
  AI_IMAGE_MODAL_FEED_ITEM,
  AI_IMAGE_MODAL_FEED_LOADER,
  AI_IMAGE_MODAL_IMAGE_STYLE,
  AI_IMAGE_MODAL_PROMPT_HELPER_POPOVER,
  AI_IMAGE_MODAL_PROMPT_HELPER_POPOVER_CLOSE,
  AI_IMAGE_MODAL_PROMPT_INPUT,
  AI_IMAGE_MODAL_ROOT,
  AI_IMAGE_MODAL_SUBMIT_BUTTON,
  AI_MODAL_CANCEL_BUTTON,
  AI_MODAL_DISCARD_MODAL,
  AI_MODAL_ERROR_CANCEL_BUTTON,
  AI_MODAL_ERROR_CONTAINER,
  AI_MODAL_ERROR_RETRY_BUTTON,
  AI_MODAL_FLOATING_MENU_POPOVER,
  AI_MODAL_LOADING_INDICATOR,
  AI_MODAL_NO_SELECTION_CONTAINER,
  AI_MODAL_PROMPT_INPUT,
  AI_MODAL_PROMPT_LIST_ITEM,
  AI_MODAL_RESULTS_ACTIONS_POPOVER,
  AI_MODAL_RESULTS_ACTIONS_POPOVER_TRIGGER,
  AI_MODAL_RESULTS_CONTENT,
  AI_MODAL_RESULTS_CONTENT_ITEM,
  AI_MODAL_RESULTS_FIST_ACTION_BUTTON,
  AI_MODAL_RESULTS_SECOND_ACTION_BUTTON,
  AI_MODAL_ROOT,
  AI_MODAL_SUBMIT_BUTTON,
  TEXT_BUTTON_AI
} from "./data-hooks.js";
const createAiTestkit = (getBase) => {
  return {
    content: {},
    contentModal: {
      getNativeElement: async () => {
        const modal = await getBase().get(dataHook(AI_MODAL_ROOT));
        return modal.getNative();
      },
      waitForElement: async () => {
        await getBase().get(dataHook(AI_MODAL_ROOT));
      },
      exists: async () => {
        try {
          const sidePanelDriver = SidePanelUniDriver(
            getBase().$(dataHook(AI_MODAL_ROOT)),
            getBase()
          );
          return sidePanelDriver.exists();
        } catch {
          return false;
        }
      },
      close: async () => {
        const sidePanelDriver = SidePanelUniDriver(getBase().$(dataHook(AI_MODAL_ROOT)), getBase());
        return sidePanelDriver.clickClose();
      },
      promptInput: InputAreaUniDriver(getBase().$(dataHook(AI_MODAL_PROMPT_INPUT)), getBase()),
      cancelButton: ButtonUniDriver(getBase().$(dataHook(AI_MODAL_CANCEL_BUTTON)), getBase()),
      submitButton: IconButtonUniDriver(getBase().$(dataHook(AI_MODAL_SUBMIT_BUTTON)), getBase()),
      promptsList: {
        atIndex: async (index) => {
          const allListItems = await getBase().getAll(dataHook(AI_MODAL_PROMPT_LIST_ITEM));
          const listItem = allListItems.at(index);
          return ListItemActionUniDriver(listItem, getBase());
        },
        count: async () => {
          try {
            const allListItems = await getBase().getAll(dataHook(AI_MODAL_PROMPT_LIST_ITEM));
            return allListItems.count();
          } catch {
            return 0;
          }
        }
      },
      loadingIndicator: {
        waitForElement: async () => {
          await getBase().get(dataHook(AI_MODAL_LOADING_INDICATOR));
        },
        exists: () => getBase().$(dataHook(AI_MODAL_LOADING_INDICATOR)).exists()
      },
      result: {
        waitForElement: async () => {
          await getBase().get(dataHook(AI_MODAL_RESULTS_CONTENT));
        },
        exists: () => {
          return getBase().$(dataHook(AI_MODAL_RESULTS_CONTENT)).exists();
        },
        atIndex: (index) => {
          const getContent = async () => {
            return await getBase().get(dataHook(AI_MODAL_RESULTS_CONTENT));
          };
          return {
            waitForElement: async () => {
              (await getContent()).$$(dataHook(AI_MODAL_RESULTS_CONTENT_ITEM)).at(index);
            },
            content: async () => {
              return (await getContent()).$$(dataHook(AI_MODAL_RESULTS_CONTENT_ITEM)).at(index).text();
            },
            actions: {
              firstActionButton: async () => ButtonUniDriver(
                (await getContent()).$$(dataHook(AI_MODAL_RESULTS_FIST_ACTION_BUTTON)).at(index),
                getBase()
              ),
              secondActionButton: async () => ButtonUniDriver(
                (await getContent()).$$(dataHook(AI_MODAL_RESULTS_SECOND_ACTION_BUTTON)).at(index),
                getBase()
              ),
              actionsMenuTrigger: async () => IconButtonUniDriver(
                (await getContent()).$$(`button${dataHook(AI_MODAL_RESULTS_ACTIONS_POPOVER_TRIGGER)}`).at(index),
                getBase()
              ),
              actionsMenu: async () => PopoverMenuUniDriver(
                (await getContent()).$$(dataHook(AI_MODAL_RESULTS_ACTIONS_POPOVER)).at(index),
                getBase()
              )
            }
          };
        }
      },
      error: {
        waitForElement: async () => {
          await getBase().get(dataHook(AI_MODAL_ERROR_CONTAINER));
        },
        exists: () => getBase().$(dataHook(AI_MODAL_ERROR_CONTAINER)).exists(),
        retryButton: ButtonUniDriver(getBase().$(dataHook(AI_MODAL_ERROR_RETRY_BUTTON)), getBase()),
        cancelButton: ButtonUniDriver(
          getBase().$(dataHook(AI_MODAL_ERROR_CANCEL_BUTTON)),
          getBase()
        )
      },
      noSelectionMessage: {
        waitForElement: async () => {
          await getBase().get(dataHook(AI_MODAL_NO_SELECTION_CONTAINER));
        },
        exists: () => getBase().$(dataHook(AI_MODAL_NO_SELECTION_CONTAINER)).exists()
      }
    },
    imageModal: {
      getNativeElement: async () => {
        const modal = await getBase().get(dataHook(AI_IMAGE_MODAL_ROOT));
        return modal.getNative();
      },
      waitForElement: async () => {
        await getBase().get(dataHook(AI_IMAGE_MODAL_ROOT));
      },
      exists: async () => {
        try {
          const sidePanelDriver = SidePanelUniDriver(
            getBase().$(dataHook(AI_IMAGE_MODAL_ROOT)),
            getBase()
          );
          return sidePanelDriver.exists();
        } catch {
          return false;
        }
      },
      close: async () => {
        const sidePanelDriver = SidePanelUniDriver(
          getBase().$(dataHook(AI_IMAGE_MODAL_ROOT)),
          getBase()
        );
        return sidePanelDriver.clickClose();
      },
      input: InputAreaUniDriver(getBase().$(dataHook(AI_IMAGE_MODAL_PROMPT_INPUT)), getBase()),
      cancelButton: ButtonUniDriver(getBase().$(dataHook(AI_IMAGE_MODAL_CANCEL_BUTTON)), getBase()),
      submitButton: ButtonUniDriver(getBase().$(dataHook(AI_IMAGE_MODAL_SUBMIT_BUTTON)), getBase()),
      imageStyle: PopoverMenuUniDriver(
        getBase().$(dataHook(AI_IMAGE_MODAL_IMAGE_STYLE)),
        getBase()
      ),
      promptHelper: {
        popover: PopoverUniDriver(
          getBase().$(dataHook(AI_IMAGE_MODAL_PROMPT_HELPER_POPOVER)),
          getBase()
        ),
        closeButton: CloseButtonUniDriver(
          getBase().$(dataHook(AI_IMAGE_MODAL_PROMPT_HELPER_POPOVER_CLOSE)),
          getBase()
        )
      },
      feed: {
        atIndex: (index) => {
          const getContent = async () => {
            return getBase().$$(dataHook(AI_IMAGE_MODAL_FEED_ITEM)).at(index);
          };
          return {
            exists: async () => {
              return (await getContent()).exists();
            },
            waitForElement: async () => {
              await (await getContent()).exists();
            },
            isLoading: async () => {
              return (await getContent()).$(dataHook(AI_IMAGE_MODAL_FEED_LOADER)).exists();
            },
            actions: {
              insertAbove: async () => ButtonUniDriver(
                (await getContent()).$(dataHook(AI_IMAGE_MODAL_ACTION_INSERT_ABOVE)),
                getBase()
              ),
              insertBelow: async () => ButtonUniDriver(
                (await getContent()).$(dataHook(AI_IMAGE_MODAL_ACTION_INSERT_BELOW)),
                getBase()
              ),
              insert: async () => ButtonUniDriver(
                (await getContent()).$(dataHook(AI_IMAGE_MODAL_ACTION_INSERT)),
                getBase()
              )
            }
          };
        }
      },
      error: {
        waitForElement: async () => {
          await getBase().get(dataHook(AI_MODAL_ERROR_CONTAINER));
        },
        exists: () => getBase().$(dataHook(AI_MODAL_ERROR_CONTAINER)).exists(),
        retryButton: ButtonUniDriver(
          getBase().$(dataHook(AI_IMAGE_MODAL_ERROR_RETRY_BUTTON)),
          getBase()
        ),
        cancelButton: ButtonUniDriver(
          getBase().$(dataHook(AI_IMAGE_MODAL_ERROR_CANCEL_BUTTON)),
          getBase()
        )
      }
    },
    flowSelectionPopover: {
      waitForElement: async () => {
        await getBase().get(dataHook(AI_FLOW_SELECTION_POPOVER));
      },
      popover: createDropdownModalUniDriver(getBase, AI_FLOW_SELECTION_POPOVER)
    },
    discardModal: MessageModalLayoutUniDriver(
      getBase().$(dataHook(AI_MODAL_DISCARD_MODAL)),
      getBase()
    ),
    toolbars: {
      createTextButtonToolbars: (getTextButtonToolbarBase) => {
        return {
          click: async () => {
            const button = await getTextButtonToolbarBase().get(dataHook(TEXT_BUTTON_AI));
            await button.click();
          }
        };
      }
    },
    popover: {
      waitForElement: async () => {
        await getBase().get(dataHook(AI_MODAL_FLOATING_MENU_POPOVER));
      },
      popover: createDropdownModalUniDriver(getBase, AI_MODAL_FLOATING_MENU_POPOVER)
    },
    integrations: {
      captionTrigger: {
        button: IconButtonUniDriver(
          getBase().$(dataHook(AI_EXPORTS_CAPTION_TRIGGER_BUTTON)),
          getBase()
        )
      },
      altTextInput: {
        input: {
          waitForElement: async () => {
            await getBase().get(dataHook(AI_EXPORTS_ALT_TEXT_INPUT_AREA));
          },
          ...InputAreaUniDriver(getBase().$(dataHook(AI_EXPORTS_ALT_TEXT_INPUT_AREA)), getBase())
        },
        generateButton: TextButtonUniDriver(
          getBase().$(dataHook(AI_EXPORTS_ALT_TEXT_GENERATE_BUTTON)),
          getBase()
        )
      }
    }
  };
};
export {
  createAiTestkit
};
//# sourceMappingURL=testkit.js.map
