"use strict";

exports.__esModule = true;
exports.CustomColumnsPanelUniDriver = CustomColumnsPanelUniDriver;
var _unidriver = require("@wix/design-system/dist/testkit/unidriver");
var _SlidingModalUni = require("../SlidingModal/SlidingModal.uni.driver");
var _DragAndDropUni = require("../DragAndDrop/DragAndDrop.uni.driver");
var _CustomFieldPopoverUni = require("../CustomFieldsPanel/CustomFieldPopover.uni.driver");
var _CustomFieldsDisabledHintUni = require("../CustomFields/CustomFieldsDisabledHint.uni.driver");
var _EmptyStateUni = require("../EmptyState/EmptyState.uni.driver");
var _ArchivedItemsPanelUni = require("../ArchivedItemsPanel/ArchivedItemsPanel.uni.driver");
function CustomColumnsPanelUniDriver(base, body) {
  const panelBase = () => base.$('[data-hook="custom-columns-panel"]');
  const panel = () => (0, _unidriver.SidePanelUniDriver)(panelBase(), body);
  const slidingModal = () => (0, _SlidingModalUni.SlidingModalUniDriver)(base.$('[data-hook="cairo-side-panel-modal"]'), body);
  const addItem = () => (0, _CustomFieldsDisabledHintUni.CustomFieldsDisabledHintUniDriver)(base, body, {
    dataHook: 'custom-columns-data-extension-add-new'
  });
  const list = () => panelBase().$('[data-hook="custom-columns-list"]');
  const getDragAndDropDriver = () => (0, _DragAndDropUni.DragAndDropUniDriver)(list());
  const items = () => panelBase().$$('[data-hook="custom-columns-list"] > div');
  const getItemAtBase = i => items().get(i);
  const getItemByIdBase = id => list().$(`[data-hook="column-item-${id}"]`);
  const getSearch = () => (0, _unidriver.SearchUniDriver)(panelBase().$('[data-hook="custom-columns-search"]'), body);
  const getNoResults = () => (0, _EmptyStateUni.EmptyStateUniDriver)(panelBase().$('[data-hook="custom-columns-no-results-state"]'), body);
  const getCheckboxAt = i => {
    const getCheckboxBase = () => getItemAtBase(i).$('[data-hook="tableListItem-checkbox"]');
    return {
      wait: timeout => getItemAtBase(i).wait(timeout),
      getLabel: () => getItemAtBase(i).$('[data-hook="tableListItem-label"]').text(),
      getTooltipContent: () => (0, _unidriver.CheckboxUniDriver)(getCheckboxBase(), body).getTooltipContent(),
      isChecked: () => (0, _unidriver.CheckboxUniDriver)(getCheckboxBase(), body).isChecked(),
      isDisabled: () => (0, _unidriver.CheckboxUniDriver)(getCheckboxBase(), body).isDisabled(),
      click: () => (0, _unidriver.CheckboxUniDriver)(getCheckboxBase(), body).click(),
      exists: () => getCheckboxBase().exists()
    };
  };
  const customFieldPopoverMenuAt = i => (0, _CustomFieldPopoverUni.CustomFieldPopoverUniDriver)(getItemAtBase(i), body);
  const getDragHandle = base => base.$('[data-hook="tableListItem-dragHandle"]');
  const getCheckboxById = id => {
    const getCheckboxBase = () => getItemByIdBase(id).$('[data-hook="tableListItem-checkbox"]');
    return {
      wait: timeout => getItemByIdBase(id).wait(timeout),
      getLabel: () => getItemByIdBase(id).$('[data-hook="tableListItem-label"]').text(),
      getTooltipContent: () => (0, _unidriver.CheckboxUniDriver)(getCheckboxBase(), body).getTooltipContent(),
      isChecked: () => (0, _unidriver.CheckboxUniDriver)(getCheckboxBase(), body).isChecked(),
      isDisabled: () => (0, _unidriver.CheckboxUniDriver)(getCheckboxBase(), body).isDisabled(),
      click: () => (0, _unidriver.CheckboxUniDriver)(getCheckboxBase(), body).click(),
      exists: () => getCheckboxBase().exists()
    };
  };
  const addNewExists = () => addItem().exists();
  const clickAddNew = () => addItem().click();

  // Archived items functionality
  const getArchivedItemsButton = () => base.$('[data-hook="custom-columns-archived-items-button"]');
  const getArchivedPanel = () => (0, _ArchivedItemsPanelUni.ArchivedItemsPanelUniDriver)(base, body, 'custom-columns');
  return {
    exists: () => panelBase().exists(),
    isOpen: () => Promise.all([slidingModal().isOpen(), panel().exists()]).then(arr => arr.every(Boolean)),
    getTitle: () => panel().getTitleText(),
    getSubtitle: () => panel().getSubtitleText(),
    clickCloseButton: () => panel().clickClose(),
    closeButtonExists: () => panel().isCloseButtonExists(),
    checkOptions: async ids => {
      for (const id of ids) {
        const checkbox = getCheckboxById(id);
        await checkbox.wait();
        await checkbox.click();
      }
    },
    getCheckboxAt,
    getCheckboxById,
    dragHandleExistsAt: i => getDragHandle(getItemAtBase(i)).exists(),
    dragHandleLockedAt: async i => (await getDragHandle(getItemAtBase(i)).$('[data-hook="drag-handle-button"]').attr('data-disabled')) === 'true',
    _dragHandleTooltipById: id => (0, _unidriver.TooltipUniDriver)(getItemByIdBase(id).$('[data-hook="tableListItem-dragHandle"]'), body),
    dragStart: async sourceIndex => getDragAndDropDriver().dragStart(await getItemAtBase(sourceIndex)),
    dragMove: () => getDragAndDropDriver().dragMove(),
    dragEnd: async targetIndex => getDragAndDropDriver().dragEnd(await getItemAtBase(targetIndex)),
    getCheckboxesCount: () => items().count(),
    getTitles: () => items().map(item => item.$('[data-hook="tableListItem-label"]').text()),
    getCustomColumnInfoIconAt: index => (0, _unidriver.InfoIconUniDriver)(getItemAtBase(index).$('[data-hook="info-icon"]'), body),
    addNewExists,
    clickAddNew,
    getAddCustomFieldCTAButton: () => addItem(),
    customFieldPopoverMenuAt,
    getCustomFieldOptionsAt: i => customFieldPopoverMenuAt(i).getCustomFieldOptionsAt(),
    customFieldPopoverMenuExistsAt: i => customFieldPopoverMenuAt(i).exists(),
    _getDragAndDropDriver: getDragAndDropDriver,
    _getItemAtBase: getItemAtBase,
    // Search functionality
    searchExists: () => getSearch().inputDriver.exists(),
    enterSearchText: value => getSearch().inputDriver.enterText(value),
    clearSearchText: () => getSearch().inputDriver.clearText(),
    getSearchText: () => getSearch().inputDriver.getText(),
    clickSearchClear: () => getSearch().inputDriver.clickClear(),
    getSearchPlaceholder: () => getSearch().inputDriver.getPlaceholder(),
    // No results functionality
    noResultsExists: () => getNoResults().exists(),
    getNoResultsTitle: () => getNoResults().getTitleText(),
    getNoResultsSubtitle: () => panelBase().$('[data-hook="custom-columns-no-results-subtitle"]').text(),
    getNoResultsResetButton: () => getNoResults().getButton('custom-columns-no-results-reset-button'),
    // Archived items functionality
    archivedItemsButtonExists: () => getArchivedItemsButton().exists(),
    clickArchivedItemsButton: () => getArchivedItemsButton().click(),
    getArchivedItemsButtonText: () => getArchivedItemsButton().$('[data-hook="tableListItem-label"]').text(),
    getArchivedPanel: () => getArchivedPanel()
  };
}
//# sourceMappingURL=CustomColumnsPanel.uni.driver.js.map