"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.selectorListUniDriverFactory = void 0;
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _unidriver = require("../utils/test-utils/unidriver");
var _LoaderUni = require("../Loader/Loader.uni.driver");
var _SelectorUni = require("../Selector/Selector.uni.driver");
var _SearchUni = require("../Search/Search.uni.driver");
var _CheckboxUni = require("../Checkbox/Checkbox.uni.driver");
var _SelectorList = require("./SelectorList.helpers");
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var selectorListUniDriverFactory = (base, body) => {
  var findInListByDataHook = dataHook => base.$("[data-hook=\"".concat(dataHook, "\"]"));
  var mainLoaderDriver = (0, _LoaderUni.loaderUniDriverFactory)(base.$("[data-hook=\"".concat(_SelectorList.dataHooks.mainLoader, "\"]")), body);
  var nextPageLoaderDriver = (0, _LoaderUni.loaderUniDriverFactory)(base.$("[data-hook=\"".concat(_SelectorList.dataHooks.nextPageLoader, "\"]")), body);
  var searchDriver = (0, _SearchUni.searchUniDriverFactory)(base.$("[data-hook=\"".concat(_SelectorList.dataHooks.search, "\"]")), body);
  var toggleAllCheckboxDriver = (0, _CheckboxUni.checkboxUniDriverFactory)(base.$("[data-hook=\"".concat(_SelectorList.dataHooks.toggleAllCheckbox, "\"]")), body);
  var getList = () => findInListByDataHook(_SelectorList.dataHooks.list);
  var getListContent = () => findInListByDataHook(_SelectorList.dataHooks.content);
  var getSelectors = () => getList().$$("[data-hook=\"".concat(_SelectorList.dataHooks.selector, "\"]"));
  var selectorDriverAt = i => (0, _SelectorUni.selectorUniDriverFactory)(getSelectors().get(i));
  var emptyState = () => findInListByDataHook(_SelectorList.dataHooks.emptyState);
  var noResultsFoundState = () => findInListByDataHook(_SelectorList.dataHooks.noResultsFoundState);
  return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base)), {}, {
    /**
     * Checks whether the main loader exists.
     * @returns {Promise<boolean>} True if main loader exists; false otherwise.
     */
    mainLoaderExists: () => mainLoaderDriver.exists(),
    /**
     * Checks whether the next page loader exists.
     * @returns {Promise<boolean>} True if next page loader exists; false otherwise.
     */
    nextPageLoaderExists: () => nextPageLoaderDriver.exists(),
    /**
     * Checks whether the search input exists.
     * @returns {Promise<boolean>} True if search input exists; false otherwise.
     */
    searchInputExists: () => searchDriver.exists(),
    /**
     * Focuses search input
     * @returns {Promise<void>} Resolves when search input is focused.
     */
    focusSearchInput: () => searchDriver.inputDriver.focus(),
    /**
     * Changes search input value
     * @param {string} value
     * @returns {Promise<void>} Resolves when search input value changes.
     */
    enterSearchValue: value => searchDriver.inputDriver.enterText(value),
    /**
     * Returns search input value
     * @returns {Promise<string>} Search input string value.
     */
    getSearchValue: () => searchDriver.inputDriver.getValue(),
    /**
     * Clicks on search input's clear button to clear value
     * @returns {Promise<void>} Resolves when clear button was clicked.
     */
    clickSearchInputClear: () => searchDriver.inputDriver.clickClear(),
    /**
     * Checks whether the toggle-all checkbox exists.
     * @param {UniDriver<any>} checkboxContainer a unidriver of the checkbox's container
     * @returns {Promise<boolean>} True if toggle-all checkbox exists; false otherwise.
     */
    toggleAllCheckboxExists: () => toggleAllCheckboxDriver.exists(),
    /**
     * Checks whether the toggle-all checkbox is checked.
     * @param {UniDriver<any>} checkboxContainer a unidriver of the checkbox's container
     * @returns {Promise<boolean>} True if toggle-all checkbox is checked; false otherwise.
     */
    isToggleAllCheckboxChecked: () => toggleAllCheckboxDriver.isChecked(),
    /**
     * Returns toggle-all checkbox label text
     * @param {UniDriver<any>} checkboxContainer a unidriver of the checkbox's container
     * @returns {Promise<string>}
     */
    getToggleAllCheckboxLabel: () => toggleAllCheckboxDriver.getLabel(),
    /**
     * Clicks on toggle-all checkbox to select/deselect all non-disabled items.
     * @param {UniDriver<any>} checkboxContainer a unidriver of the checkbox's container
     * @returns {Promise<void>} Resolves when toggle-all checkbox was clicked.
     */
    clickToggleAllCheckbox: () => toggleAllCheckboxDriver.click(),
    /**
     * Checks whether empty state is shown.
     * @returns {Promise<boolean>} True if empty state is shown; false otherwise.
     */
    showsEmptyState: () => emptyState().exists(),
    /**
     * Gets empty state.
     * @returns {Promise<HTMLElement>}
     */
    getEmptyState: () => emptyState()._prop('firstChild'),
    /**
     * Checks whether no results found state is shown.
     * @returns {Promise<boolean>} True if no results found state is shown; false otherwise.
     */
    showsNoResultsFoundState: () => noResultsFoundState().exists(),
    /**
     * Gets no results found state.
     * @returns {Promise<HTMLElement>}
     */
    getNoResultsFoundState: () => noResultsFoundState()._prop('firstChild'),
    /**
     * Checks whether the list exists.
     * @returns {Promise<boolean>} True if list exists; false otherwise.
     */
    listExists: () => getList().exists(),
    /**
     * Returns the number of items in the list.
     * @returns {Promise<number>}
     */
    numberOfItemsInList: () => getSelectors().count(),
    /**
     * Toggles selector of the item at the passed index.
     * @param {number} i Item index
     * @returns {Promise<void>} Resolves when selector is toggled.
     */
    toggleSelectorAt: i => selectorDriverAt(i).toggle(),
    /**
     * Checks whether the selector of the item at the passed index is checked.
     * @param {number} i Item index
     * @returns {Promise<boolean>}
     */
    isSelectorCheckedAt: i => selectorDriverAt(i).isChecked(),
    /**
     * Checks whether the selector of the item at the passed index is in indeterminate mode.
     * @param {number} i Item index
     * @returns {Promise<boolean>}
     */
    isSelectorIsIndeterminateAt: i => selectorDriverAt(i).isIndeterminate(),
    /**
     * Checks whether the selector of the item at the passed index is disabled.
     * @param {number} i Item index
     * @returns {Promise<boolean>}
     */
    isSelectorDisabledAt: i => selectorDriverAt(i).isDisabled(),
    /**
     * Gets the selector title text of the item at the passed index.
     * @param {number} i Item index
     * @returns {Promise<string>}
     */
    getSelectorTitleAt: i => selectorDriverAt(i).titleTextDriver().getText(),
    /**
     * Gets the selector subtitle text of the item at the passed index.
     * @param {number} i Item index
     * @returns {Promise<string>}
     */
    getSelectorSubtitleAt: i => selectorDriverAt(i).subtitleTextDriver().getText(),
    /**
     * Gets the selector extra node element of the item at the passed index.
     * @param {number} i Item index
     * @returns {Promise<HTMLElement>}
     */
    getSelectorExtraNodeAt: i => selectorDriverAt(i).getExtraNode(),
    /**
     * Gets the selector image element of the item at the passed index.
     * @param {number} i Item index
     * @returns {Promise<HTMLElement>}
     */
    getSelectorImageAt: i => selectorDriverAt(i).getImage(),
    /**
     * Triggers "scroll" event on the list.
     * @returns {Promise<boolean>}.
     */
    scrollDown: function () {
      var _scrollDown = (0, _asyncToGenerator2.default)(function* () {
        return (yield getListContent().getNative()).dispatchEvent(new Event('scroll'));
      });
      function scrollDown() {
        return _scrollDown.apply(this, arguments);
      }
      return scrollDown;
    }(),
    /**
     * Gets the selector tooltip text of the item at the passed index.
     * @param {number} i Item index
     * @returns {Promise<string | null>}
     */
    getSelectorTooltipTextAt: i => selectorDriverAt(i).getTooltipText()
  });
};
exports.selectorListUniDriverFactory = selectorListUniDriverFactory;
//# sourceMappingURL=SelectorList.uni.driver.js.map