"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var social_polls_testkit_exports = {};
__export(social_polls_testkit_exports, {
  createPollsTestkit: () => createPollsTestkit
});
module.exports = __toCommonJS(social_polls_testkit_exports);
var import_unidriver = require("@wix/design-system/dist/testkit/unidriver.js");
var import_ricos_types = require("./../../ricos-types/index.js");
var import_data_hooks = require("./../../_shared/data-hooks.js");
var import_dropdown_modal_uni_driver = require("./../../_shared/dropdown-modal/dropdown-modal-uni-driver.js");
var import_wix_rich_content_common = require("./../../wix-rich-content-common/index.js");
var import_data_hooks2 = require("../data-hooks.js");
var import_get_add_buttons = require("../get-add-buttons.js");
var import_social_polls_settings_tab_unidriver = require("./social-polls-settings-tab.unidriver.js");
const createPollsTestkit = (getBase) => {
  const getPoll = async (index, options) => {
    const polls = await getBase().getAll((0, import_wix_rich_content_common.dataHook)(import_data_hooks2.ROOT), options);
    return polls.at(index);
  };
  return {
    content: {
      atIndex: (index) => {
        return {
          exists: async (options) => {
            try {
              const poll = await getPoll(index, options);
              return poll.exists();
            } catch {
              return false;
            }
          },
          clickOnPoll: async () => (await getPoll(index)).click(),
          getDirection: async () => {
            const poll = await getPoll(index);
            return poll.attr("dir");
          },
          getStyle: async () => {
            const poll = await getPoll(index);
            return poll.attr("style");
          },
          questionImageExists: async () => {
            try {
              const image = await getBase().get((0, import_wix_rich_content_common.dataHook)(import_data_hooks2.POLLS_QUESTION_IMAGE));
              return image.exists();
            } catch {
              return false;
            }
          },
          answerImageExist: async (index2) => {
            try {
              const images = await getBase().getAll((0, import_wix_rich_content_common.dataHook)(import_data_hooks2.POLLS_ANSWER_IMAGE));
              return images.at(index2).exists();
            } catch {
              return false;
            }
          },
          multipleVotesTextExists: async () => {
            try {
              const text = await getBase().get((0, import_wix_rich_content_common.dataHook)(import_data_hooks2.POLLS_MULTIPLE_ANSWER_TEXT));
              return text.exists();
            } catch {
              return false;
            }
          },
          editor: {
            setQuestionText: async (text) => {
              const questionInput = await getBase().get((0, import_wix_rich_content_common.dataHook)(import_data_hooks2.POLLS_QUESTION_TEXT_INPUT));
              await questionInput.enterValue(text);
            },
            setAnswerText: async (index2, text) => {
              const answerInput = await getBase().getAll((0, import_wix_rich_content_common.dataHook)(import_data_hooks2.POLLS_ANSWER_TEXT_INPUT));
              await answerInput.at(index2).enterValue(text);
            },
            addAnswer: async () => {
              const button = await getBase().get((0, import_wix_rich_content_common.dataHook)(import_data_hooks2.POLLS_ADD_ANSWER_BUTTON));
              await button.click();
            },
            removeAnswer: async (index2) => {
              const answerInput = await getBase().getAll((0, import_wix_rich_content_common.dataHook)(import_data_hooks2.POLLS_ANSWER_TEXT_INPUT));
              await answerInput.at(index2).click();
              const button = await getBase().getAll((0, import_wix_rich_content_common.dataHook)(import_data_hooks2.POLLS_REMOVE_ANSWER_BUTTON));
              await button.at(index2).click();
            }
          },
          preview: {
            getQuestionText: async () => {
              const question = await getBase().get((0, import_wix_rich_content_common.dataHook)(import_data_hooks2.POLLS_QUESTION_TEXT_INPUT));
              return question.text();
            },
            getAnswerText: async (index2) => {
              const answers = await getBase().getAll((0, import_wix_rich_content_common.dataHook)(import_data_hooks2.POLLS_ANSWER_TEXT_INPUT));
              return answers.at(index2).text();
            },
            countAnswers: async () => {
              const items = await getBase().getAll((0, import_wix_rich_content_common.dataHook)(import_data_hooks2.POLLS_ANSWER_ITEMS));
              return items.count();
            },
            votePercentageExists: async (index2) => {
              try {
                const items = await getBase().getAll((0, import_wix_rich_content_common.dataHook)(import_data_hooks2.POLLS_ITEM_PERCENTAGE_PREVIEW));
                return items.at(index2).exists();
              } catch {
                return false;
              }
            }
          }
        };
      }
    },
    presetSelectorModal: {
      waitForElement: async () => {
        await getBase().get((0, import_wix_rich_content_common.dataHook)(import_data_hooks2.INSERT_POLL_MODAL));
      },
      getSelectorThumbnail: async (type) => {
        const galleryLayout = await getBase().get(
          (0, import_wix_rich_content_common.dataHook)(`${import_data_hooks2.INSERT_POLL_MODAL_THUMBNAIL}${type}`)
        );
        return (0, import_unidriver.ThumbnailUniDriver)(galleryLayout, getBase());
      }
    },
    settings: (0, import_social_polls_settings_tab_unidriver.createPollsSettingsUniDriver)(getBase),
    toolbars: {
      createAddButtonToolbars: (getAddButtonToolbarBase) => ({
        click: async () => {
          const pollsPluginButton = await getAddButtonToolbarBase().get(
            (0, import_wix_rich_content_common.dataHook)(import_data_hooks2.INSERT_POLL_BUTTON)
          );
          await pollsPluginButton.click();
        },
        toolbarsToAddIn: import_get_add_buttons.toolbarsToAddIn
      }),
      createPluginToolbar: (getPluginToolbarBase) => ({
        clickDelete: async () => {
          const deleteButton = await getPluginToolbarBase(import_ricos_types.RicosPluginToolbarNames.POLL).get(
            (0, import_wix_rich_content_common.dataHook)(import_data_hooks.PLUGIN_TOOLBAR_DELETE_BUTTON)
          );
          return deleteButton.click();
        },
        exists: async () => {
          try {
            return (await getPluginToolbarBase(import_ricos_types.RicosPluginToolbarNames.POLL)).exists();
          } catch {
            return false;
          }
        },
        clickLayoutSelectionDropdown: async () => {
          const settings = await getBase().get((0, import_wix_rich_content_common.dataHook)(import_data_hooks2.PLUGIN_TOOLBAR_LAYOUT_DROPDOWN_BUTTON));
          await settings.click();
        },
        layoutSelectionDropdown: (0, import_dropdown_modal_uni_driver.createDropdownModalUniDriver)(getBase),
        clickSettings: async () => {
          const button = await getBase().get((0, import_wix_rich_content_common.dataHook)(import_data_hooks.PLUGIN_TOOLBAR_SETTINGS_BUTTON));
          await button.click();
        }
      })
    }
  };
};
//# sourceMappingURL=social-polls.testkit.js.map
