"use strict";

exports.__esModule = true;
exports.MultiLevelSortingPanelUniDriver = MultiLevelSortingPanelUniDriver;
exports.default = void 0;
var _unidriver = require("@wix/design-system/dist/testkit/unidriver");
var _SlidingModalUni = require("../SlidingModal/SlidingModal.uni.driver");
var _DragAndDropUni = require("../DragAndDrop/DragAndDrop.uni.driver");
var _unidriver2 = require("../../unidriver");
function MultiLevelSortingPanelUniDriver(base, body) {
  const panelBase = () => base.$('[data-hook="multi-level-sorting-panel"]');
  const panel = () => (0, _unidriver.SidePanelUniDriver)(panelBase(), body);
  const slidingModal = () => (0, _SlidingModalUni.SlidingModalUniDriver)(base.$('[data-hook="cairo-side-panel-modal"]'), body);
  const list = () => panelBase().$('[data-hook="multi-level-sorting-list"]');
  const getDragAndDropDriver = () => (0, _DragAndDropUni.DragAndDropUniDriver)(list());
  const items = () => panelBase().$$('[data-hook="multi-level-sorting-list"] > div');
  const getItemAtBase = i => items().get(i);
  const addItemButton = () => (0, _unidriver.AddItemUniDriver)(base.$(`[data-hook="multi-level-sorting-add-sort"]`), body);
  const clickSortRemoveAtIndex = index => (0, _unidriver.IconButtonUniDriver)(getItemAtBase(index).$(`[data-hook="multi-level-sorting-remove-sort"]`), body).click();
  const changeSortOrderAtIndex = (index, order) => {
    const dropdown = (0, _unidriver.DropdownUniDriver)(getItemAtBase(index).$(`[data-hook="multi-level-sorting-select-order"]`), body);
    return dropdown.dropdownLayoutDriver.clickAtOption(order === 'asc' ? 0 : 1);
  };
  const getSortOrderAtIndex = async index => {
    const dropdown = (0, _unidriver.DropdownUniDriver)(getItemAtBase(index).$(`[data-hook="multi-level-sorting-select-order"]`), body);
    return dropdown.dropdownLayoutDriver.getSelectedOptionId();
  };
  const changeColumnAtIndex = (index, columnIndex) => {
    const dropdown = (0, _unidriver.DropdownUniDriver)(getItemAtBase(index).$(`[data-hook="multi-level-sorting-select-column-${index}"]`), body);
    return dropdown.dropdownLayoutDriver.clickAtOption(columnIndex);
  };
  const getColumnAtIndex = index => {
    const dropdown = (0, _unidriver.DropdownUniDriver)(getItemAtBase(index).$(`[data-hook="multi-level-sorting-select-column-${index}"]`), body);
    return dropdown.dropdownLayoutDriver.getSelectedOptionId();
  };
  return {
    /**
     * Wait until root element to exist
     * @param timeout - time to wait until bailing
     */
    wait: timeout => base.wait(timeout),
    ...(0, _unidriver2.baseUniDriverFactory)(base),
    /** Checks if the panel exist */
    exists: () => panelBase().exists(),
    /** Checks if the SidePanel is open */
    isOpen: () => Promise.all([slidingModal().isOpen(), panel().exists()]).then(arr => arr.every(Boolean)),
    getTitle: () => panel().getTitleText(),
    getSubtitle: () => panel().getSubtitleText(),
    clickCloseButton: () => panel().clickClose(),
    closeButtonExists: () => panel().isCloseButtonExists(),
    clickAddSortButton: () => addItemButton().click(),
    /** Removes a sort item at index */
    clickSortRemoveAtIndex,
    /** Changes a sort order at index */
    changeSortOrderAtIndex,
    getSortOrderAtIndex,
    /** Changes a sort column at index */
    changeColumnAtIndex,
    getColumnAtIndex,
    getItemsCount: () => items().count(),
    dragHandleExistsAt: i => getItemAtBase(i).$('[data-hook="multi-level-sorting-item-drag-handle"]').exists(),
    dragStart: async sourceIndex => getDragAndDropDriver().dragStart(await getItemAtBase(sourceIndex)),
    dragMove: () => getDragAndDropDriver().dragMove(),
    dragEnd: async targetIndex => getDragAndDropDriver().dragEnd(await getItemAtBase(targetIndex))
  };
}
var _default = exports.default = MultiLevelSortingPanelUniDriver;
//# sourceMappingURL=MultiLevelSortingPanel.uni.driver.js.map