"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = exports.PopoverMenuDriver = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _DropdownBaseUni = require("../DropdownBase/DropdownBase.uni.driver");
var _DropdownLayoutUni = require("../DropdownLayout/DropdownLayout.uni.driver");
var _PopoverNextUni = require("../PopoverNext/PopoverNext.uni.driver");
var _unidriver = require("../utils/test-utils/unidriver");
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 PopoverMenuDriver = (base, body) => {
  var dropdownBaseTestkit = (0, _DropdownBaseUni.dropdownBaseDriverFactory)(base, body);
  var getContentElement = /*#__PURE__*/function () {
    var _ref = (0, _asyncToGenerator2.default)(function* () {
      return (0, _PopoverNextUni.popoverNextUniDriverFactory)(base, body).getContentElementUniDriver();
    });
    return function getContentElement() {
      return _ref.apply(this, arguments);
    };
  }();
  var createDropdownLayoutDriver = /*#__PURE__*/function () {
    var _ref2 = (0, _asyncToGenerator2.default)(function* () {
      return (0, _DropdownLayoutUni.dropdownLayoutDriverFactory)((yield getContentElement()).$("[data-hook=\"dropdown-base-dropdownlayout\"]"), body);
    });
    return function createDropdownLayoutDriver() {
      return _ref2.apply(this, arguments);
    };
  }();
  return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base)), {}, {
    /** Returns true of popoverMenu exists */
    exists: () => dropdownBaseTestkit.exists(),
    /** Returns trigger element */
    getTriggerElement: dataHook => base.$("[data-hook=\"".concat(dataHook, "\"]")),
    /** Select a specific option by its index (requires the menu to be opened) */
    clickAtChild: index => dropdownBaseTestkit.selectOption(index),
    /** Select a specific option by its data-hook (requires the menu to be opened) */
    clickAtChildByDataHook: dataHook => dropdownBaseTestkit.selectOptionByDataHook(dataHook),
    /** Return true if the menu is opened */
    isMenuOpen: () => dropdownBaseTestkit.isDropdownShown(),
    /** Returns children count */
    childrenCount: () => dropdownBaseTestkit.optionsCount(),
    /** Returns text of <PopoverMenu.MenuItem/> of a specific index */
    itemContentAt: function () {
      var _itemContentAt = (0, _asyncToGenerator2.default)(function* (index) {
        var dropdownLayoutDriver = yield createDropdownLayoutDriver();
        var optionsDrivers = yield dropdownLayoutDriver.options();
        return yield optionsDrivers[index].content();
      });
      function itemContentAt(_x) {
        return _itemContentAt.apply(this, arguments);
      }
      return itemContentAt;
    }(),
    isListItemFocused: function () {
      var _isListItemFocused = (0, _asyncToGenerator2.default)(function* (position) {
        return createDropdownLayoutDriver().then(tsk => tsk.isListItemFocused(position));
      });
      function isListItemFocused(_x2) {
        return _isListItemFocused.apply(this, arguments);
      }
      return isListItemFocused;
    }(),
    /** Returns the content element (`<Popover.Content/>`) */
    getContentElement
  });
};
exports.PopoverMenuDriver = PopoverMenuDriver;
var _default = exports.default = PopoverMenuDriver;
//# sourceMappingURL=PopoverMenu.uni.driver.js.map