"use strict";

exports.__esModule = true;
exports.ManageTagsModalUniDriver = ManageTagsModalUniDriver;
var _unidriver = require("../../../../unidriver");
var _unidriver2 = require("@wix/design-system/dist/testkit/unidriver");
function ManageTagsModalUniDriver(base, body) {
  const modalBase = () => body.$(`[data-hook="manage-tags-modal-layout"]`);
  const getManageTagsModal = () => (0, _unidriver2.CustomModalLayoutUniDriver)(modalBase(), body);
  const exists = () => getManageTagsModal().exists();
  const getModalTitle = () => getManageTagsModal().getTitleText();
  const getTags = () => body.$$(`[data-hook="manage-tags-modal-tag"]`);
  const getTagsCount = () => getTags().count();
  const getTagByIdx = idx => (0, _unidriver2.TagUniDriver)(getTags().get(idx), body);
  const getTagById = tagId => (0, _unidriver2.TagUniDriver)(body.$(`[id="${tagId}"]`), body);
  const getTagRows = () => body.$$(`[data-hook="manage-tags-modal-tag-row"]`);
  const getTagRowByIdx = idx => getTagRows().get(idx);
  const clickTagRenameButtonByIdx = idx => (0, _unidriver2.IconButtonUniDriver)(getTagRowByIdx(idx).$(`[data-hook="manage-tags-modal-tag-action-edit"]`), body).click();
  const clickTagDeleteButtonByIdx = idx => (0, _unidriver2.IconButtonUniDriver)(getTagRowByIdx(idx).$(`[data-hook="manage-tags-modal-tag-action-delete"]`), body).click();
  const getCreateBtnDriver = () => (0, _unidriver2.TextButtonUniDriver)(body.$(`[data-hook="manage-tags-modal-create-btn"]`), body);
  const getNotificationDriver = () => {
    const notificationBase = body.$(`[data-hook="manage-tags-modal-notification"]`);
    const statusToast = (0, _unidriver2.StatusToastUniDriver)(notificationBase, body);
    const actionButton = (0, _unidriver2.TextButtonUniDriver)(notificationBase.$(`[data-hook="manage-tags-modal-notification-action"]`), body);
    return {
      ...statusToast,
      getText: () => notificationBase.$('[data-hook="manage-tags-modal-notification-message"]').text(),
      clickTextButton: () => actionButton.click(),
      getTextButtonLabel: () => actionButton.getButtonTextContent()
    };
  };
  const getNotificationButtonExists = () => body.$(`[data-hook="manage-tags-modal-notification"]`).$(`[data-hook="manage-tags-modal-notification-action"]`).exists();
  const clickCloseButton = async () => {
    await getManageTagsModal().clickCloseButton();
  };
  const getSearchDriver = () => (0, _unidriver2.SearchUniDriver)(body.$('[data-hook="manage-tags-modal-search"]'), body);
  const getAddItem = () => (0, _unidriver2.AddItemUniDriver)(body.$(`[data-hook="manage-tags-modal-list-add"]`), body);
  const getFormField = () => (0, _unidriver2.FormFieldUniDriver)(body.$(`[data-hook="manage-tags-modal-tag-form-field"]`), body);
  const getListItemEditable = () => (0, _unidriver2.ListItemEditableUniDriver)(body.$(`[data-hook="manage-tags-modal-tag-editable"]`), body);
  const getMessageModalLayout = () => (0, _unidriver2.MessageModalLayoutUniDriver)(body.$(`[data-hook="manage-tags-modal-confirm-delete-modal"]`), body);

  // Dispatches a scroll event on the tags list container — the element the
  // infinite-scroll listener subscribes to. jsdom can't emit real scrolls, so
  // we trigger it directly (encapsulated here so specs stay DOM-free).
  const scrollListToBottom = async () => {
    const listElement = await body.$(`[data-hook="manage-tags-modal-tags-list"]`).getNative();
    listElement.dispatchEvent(new Event('scroll'));
  };
  return {
    ...(0, _unidriver.baseUniDriverFactory)(base),
    exists,
    getTagsCount,
    getTagByIdx,
    getTagById,
    getModalTitle,
    getCreateBtnDriver,
    getNotificationDriver,
    getNotificationButtonExists,
    clickCloseButton,
    getSearchDriver,
    getAddItem,
    getFormField,
    getListItemEditable,
    clickTagRenameButtonByIdx,
    clickTagDeleteButtonByIdx,
    getTagRows,
    getMessageModalLayout,
    scrollListToBottom
  };
}
//# sourceMappingURL=ManageTagsModal.uni.driver.js.map