import {
  RadioUniDriver,
  ToggleSwitchUniDriver
} from "@wix/design-system/dist/testkit/unidriver.js";
import { RicosPluginToolbarNames } from "./../../ricos-types/index.js";
import {
  PLUGIN_TOOLBAR_DELETE_BUTTON,
  PLUGIN_TOOLBAR_SETTINGS_BUTTON
} from "./../../_shared/data-hooks.js";
import { dataHook } from "./../../wix-rich-content-common/index.js";
import {
  COLLAPSIBLE_LIST_ITEM,
  INSERT_COLLAPSIBLE_LIST_BUTTON,
  NEW_PAIR_BUTTON,
  ROOT,
  SETTINGS_EXPAND_ONLY_ONE_TOGGLE,
  SETTINGS_INITIAL_EXPANDED_ALL,
  SETTINGS_INITIAL_EXPANDED_FIRST,
  SETTINGS_INITIAL_EXPANDED_NONE,
  SETTINGS_MODAL
} from "../data-hooks.js";
import { toolbarsToAddIn } from "../get-add-buttons.js";
import { createCollapsibleListItemUniDriver } from "./collapsible-list-item.uni.driver.js";
const createCollapsibleListTestkit = (getBase) => {
  const getCollapsibleList = async (index, options) => {
    const collapsibleList = await getBase().getAll(dataHook(ROOT), options);
    return collapsibleList.at(index);
  };
  const getSettingsModal = async () => await getBase().get(dataHook(SETTINGS_MODAL));
  const getModalBase = () => getBase().$(dataHook(SETTINGS_MODAL));
  return {
    content: {
      atIndex: (index) => {
        return {
          exists: async (options) => {
            try {
              const collapsibleList = await getCollapsibleList(index, options);
              return collapsibleList.exists();
            } catch {
              return false;
            }
          },
          getItemsCount: async () => {
            const collapsibleList = await getCollapsibleList(index);
            const listItems = await collapsibleList.getAll(dataHook(COLLAPSIBLE_LIST_ITEM));
            return listItems.count();
          },
          getExpandedListItemsCount: async () => {
            const collapsibleList = await getCollapsibleList(index);
            const listItems = await collapsibleList.$$(
              dataHook([COLLAPSIBLE_LIST_ITEM, "expanded"])
            );
            return listItems.count();
          },
          addNewItem: async () => {
            const collapsibleList = await getCollapsibleList(index);
            const addNewItemButton = await collapsibleList.get(dataHook(NEW_PAIR_BUTTON));
            await addNewItemButton.click();
          },
          addNewItemButtonExists: async () => {
            try {
              const collapsibleList = await getCollapsibleList(index);
              const button = await collapsibleList.get(dataHook(NEW_PAIR_BUTTON));
              return button.exists();
            } catch {
              return false;
            }
          },
          listItem: createCollapsibleListItemUniDriver(getBase)
        };
      }
    },
    toolbar: {},
    modal: {
      exists: async () => {
        try {
          const settingsModal = await getSettingsModal();
          return settingsModal.exists();
        } catch {
          return false;
        }
      },
      initialExpandedItems: {
        allOption: RadioUniDriver(
          getModalBase().$(dataHook(SETTINGS_INITIAL_EXPANDED_ALL)),
          getBase()
        ),
        firstOption: RadioUniDriver(
          getModalBase().$(dataHook(SETTINGS_INITIAL_EXPANDED_FIRST)),
          getBase()
        ),
        noneOption: RadioUniDriver(
          getModalBase().$(dataHook(SETTINGS_INITIAL_EXPANDED_NONE)),
          getBase()
        )
      },
      expandOnlyOneToggle: ToggleSwitchUniDriver(
        getModalBase().$(dataHook(SETTINGS_EXPAND_ONLY_ONE_TOGGLE)),
        getBase()
      )
    },
    toolbars: {
      createAddButtonToolbars: (getAddButtonToolbarBase) => ({
        click: async () => {
          const collapsibleListButton = await getAddButtonToolbarBase().get(
            dataHook(INSERT_COLLAPSIBLE_LIST_BUTTON)
          );
          await collapsibleListButton.click();
        },
        toolbarsToAddIn
      }),
      createPluginToolbar: (getPluginToolbarBase) => ({
        clickEdit: async () => {
          const editButton = await getPluginToolbarBase(
            RicosPluginToolbarNames.COLLAPSIBLE_LIST
          ).get(dataHook(PLUGIN_TOOLBAR_SETTINGS_BUTTON), {
            timeout: 5e3
          });
          return editButton.click();
        },
        clickDelete: async () => {
          const deleteButton = await getPluginToolbarBase(
            RicosPluginToolbarNames.COLLAPSIBLE_LIST
          ).get(dataHook(PLUGIN_TOOLBAR_DELETE_BUTTON), {
            timeout: 5e3
          });
          return deleteButton.click();
        },
        exists: async () => {
          try {
            const pluginToolbar = await getPluginToolbarBase(
              RicosPluginToolbarNames.COLLAPSIBLE_LIST
            );
            return pluginToolbar.exists();
          } catch {
            return false;
          }
        }
      })
    }
  };
};
export {
  createCollapsibleListTestkit
};
//# sourceMappingURL=collapsible-list.testkit.js.map
