"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.modalSelectorLayoutUniDriverFactory = 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 _SelectorListUni = require("../SelectorList/SelectorList.uni.driver");
var _LoaderUni = require("../Loader/Loader.uni.driver");
var _SelectorUni = require("../Selector/Selector.uni.driver");
var _SearchUni = require("../Search/Search.uni.driver");
var _TextUni = require("../Text/Text.uni.driver");
var _SelectorList = require("../SelectorList/SelectorList.helpers");
var _ModalSelectorLayout = require("./ModalSelectorLayout.helpers");
var _CheckboxUni = require("../Checkbox/Checkbox.uni.driver");
var _ButtonUni = require("../Button/Button.uni.driver");
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 modalSelectorLayoutUniDriverFactory = (base, body) => {
  var findInModalByDataHook = dataHook => base.$("[data-hook=\"".concat(dataHook, "\"]"));
  var selectorListDriver = () => (0, _SelectorListUni.selectorListUniDriverFactory)(base.$("[data-hook=\"".concat(_ModalSelectorLayout.dataHooks.selectorList, "\"]")), body);
  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 cancelButtonDriver = () => (0, _ButtonUni.buttonDriverFactory)(base.$('[data-hook="cancellation-button"]'), body);
  var okButtonDriver = () => (0, _ButtonUni.buttonDriverFactory)(base.$('[data-hook="confirmation-button"]'), body);
  var subtitleTextDriver = () => (0, _TextUni.textUniDriverFactory)(base.$("[data-hook=\"".concat(_SelectorList.dataHooks.subtitle, "\"]")), body);
  var searchDriver = () => (0, _SearchUni.searchUniDriverFactory)(base.$("[data-hook=\"".concat(_SelectorList.dataHooks.search, "\"]")), body);
  var getList = () => findInModalByDataHook(_SelectorList.dataHooks.list);
  var getSelectorListContent = () => findInModalByDataHook(_SelectorList.dataHooks.content);
  var getSelectors = () => getList().$$("[data-hook=\"".concat(_SelectorList.dataHooks.selector, "\"]"));
  var selectorDriverAt = i => (0, _SelectorUni.selectorUniDriverFactory)(getSelectors().get(i));
  var _footerSelector = (0, _CheckboxUni.checkboxUniDriverFactory)(base.$("[data-hook=\"".concat(_SelectorList.dataHooks.toggleAllCheckbox, "\"]"), body));
  return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base)), {}, {
    /**
     * Gets main loader driver.
     * @returns {LoaderUniDriver}
     */
    mainLoaderDriver,
    /**
     * Gets next page loader driver.
     * @returns {LoaderUniDriver}
     */
    nextPageLoaderDriver,
    /**
     * Gets cancel button driver.
     * @returns {ButtonUniDriver}
     */
    cancelButtonDriver,
    /**
     * Gets ok button driver.
     * @returns {ButtonUniDriver}
     */
    okButtonDriver,
    /**
     * Gets search driver.
     * @returns {SearchUniDriver}
     */
    searchDriver,
    /**
     * Gets subtitle text driver.
     * @returns {TextUniDriver}
     */
    subtitleTextDriver,
    /**
     * Gets title text.
     * @returns {Promise<string>}
     */
    getTitle: () => findInModalByDataHook('header-layout-title').text(),
    /**
     * Clicks "x" button.
     * @returns {Promise<void>}
     */
    clickOnClose: () => base.$('[data-hook="header-close-button"]').click(),
    /**
     * Checks weather empty state is shown.
     * @returns {Promise<boolean>} True if empty state is shown; false otherwise.
     */
    showsEmptyState: () => selectorListDriver().showsEmptyState(),
    /**
     * Gets empty state.
     * @returns {Promise<HTMLElement>}
     */
    getEmptyState: () => selectorListDriver().getEmptyState(),
    /**
     * Checks weather no results found state is shown.
     * @returns {Promise<boolean>} True if no results found state is shown; false otherwise.
     */
    showsNoResultsFoundState: () => selectorListDriver().showsNoResultsFoundState(),
    /**
     * Gets no results found state.
     * @returns {Promise<HTMLElement>}
     */
    getNoResultsFoundState: () => selectorListDriver().getNoResultsFoundState(),
    /**
     * Checks weather the list exists.
     * @returns {Promise<boolean>} True if list exists; false otherwise.
     */
    listExists: () => selectorListDriver().listExists(),
    /**
     * Returns the number of items in the list.
     * @returns {Promise<number>}
     */
    numberOfItemsInList: () => selectorListDriver().numberOfItemsInList(),
    /**
     * Gets the selector driver of the item at the passed index.
     * @param {number} i Item index
     * @returns {SelectorUniDriver} The selector driver.
     */
    getSelectorDriverAt: i => selectorDriverAt(i),
    /**
     * Triggers "scroll" event on the list.
     * @returns {Promise<boolean>}.
     */
    scrollDown: function () {
      var _scrollDown = (0, _asyncToGenerator2.default)(function* () {
        return (yield getSelectorListContent().getNative()).dispatchEvent(new Event('scroll'));
      });
      function scrollDown() {
        return _scrollDown.apply(this, arguments);
      }
      return scrollDown;
    }(),
    /**
     * Gets footer selector's driver.
     * @returns {CheckboxUniDriver}
     */
    footerSelector: () => _footerSelector
  });
};
exports.modalSelectorLayoutUniDriverFactory = modalSelectorLayoutUniDriverFactory;
//# sourceMappingURL=ModalSelectorLayout.uni.driver.js.map