"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.sidebarSubMenuNextDriverFactory = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _unidriver = require("../utils/test-utils/unidriver");
var _constants = require("./constants");
var _SidebarItemButtonNextUni = require("../SidebarItemNext/SidebarItemButtonNext.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 sidebarSubMenuNextDriverFactory = (base, body) => {
  var findByHookWithin = /*#__PURE__*/function () {
    var _ref = (0, _asyncToGenerator2.default)(function* (dataHook) {
      return (0, _unidriver.findByHook)(base, (0, _constants.getCompoundDataHook)(yield base.attr('data-hook'), dataHook));
    });
    return function findByHookWithin(_x) {
      return _ref.apply(this, arguments);
    };
  }();
  return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base, body)), {}, {
    /**
     * Returns true if submenu is expanded
     * @returns {Promise<boolean>}
     */
    isExpanded: function () {
      var _isExpanded = (0, _asyncToGenerator2.default)(function* () {
        return (yield base.attr('data-open')) === 'true';
      });
      function isExpanded() {
        return _isExpanded.apply(this, arguments);
      }
      return isExpanded;
    }(),
    /**
     * Clicks on the sidebar submenu
     * @returns {Promise<any>}
     */
    click: function () {
      var _click = (0, _asyncToGenerator2.default)(function* () {
        return (yield findByHookWithin(_constants.dataHooks.sidebarItem)).click();
      });
      function click() {
        return _click.apply(this, arguments);
      }
      return click;
    }(),
    /**
     * Triggers a mouseEnter event
     * @return {Promise<void>}
     */
    triggerMouseEnter: function () {
      var _triggerMouseEnter = (0, _asyncToGenerator2.default)(function* () {
        var trigger = yield findByHookWithin(_constants.dataHooks.submenuPopover);

        // We don't render the popover trigger if the submenu is empty, but we
        // still want to expose the `triggerMouseEnter` for backwards
        // compatibility.
        if (yield trigger.exists()) {
          yield trigger.hover();
        }
      });
      function triggerMouseEnter() {
        return _triggerMouseEnter.apply(this, arguments);
      }
      return triggerMouseEnter;
    }(),
    /**
     * Returns if the sidebar submenu is disabled
     * @returns {Promise<boolean>}
     */
    isDisabled: function () {
      var _isDisabled = (0, _asyncToGenerator2.default)(function* () {
        var button = yield findByHookWithin(_constants.dataHooks.sidebarItem);
        var buttonDriver = (0, _SidebarItemButtonNextUni.sidebarItemButtonNextDriverFactory)(button);
        return yield buttonDriver.isDisabled();
      });
      function isDisabled() {
        return _isDisabled.apply(this, arguments);
      }
      return isDisabled;
    }(),
    /**
     * Returns the submenu title
     * @returns {Promise<any>}
     */
    getTitle: function () {
      var _getTitle = (0, _asyncToGenerator2.default)(function* (dataHook) {
        return yield (0, _unidriver.findByHook)(base, dataHook);
      });
      function getTitle(_x2) {
        return _getTitle.apply(this, arguments);
      }
      return getTitle;
    }(),
    /**
     * Returns the submenu title text
     * @returns {Promise<string>}
     */
    getTitleText: function () {
      var _getTitleText = (0, _asyncToGenerator2.default)(function* () {
        return (yield findByHookWithin(_constants.dataHooks.sidebarItem)).text();
      });
      function getTitleText() {
        return _getTitleText.apply(this, arguments);
      }
      return getTitleText;
    }(),
    isQuickNavOpen: function () {
      var _isQuickNavOpen = (0, _asyncToGenerator2.default)(function* () {
        return (yield base.attr('data-quick-nav-open')) === 'true';
      });
      function isQuickNavOpen() {
        return _isQuickNavOpen.apply(this, arguments);
      }
      return isQuickNavOpen;
    }()
  });
};
exports.sidebarSubMenuNextDriverFactory = sidebarSubMenuNextDriverFactory;
//# sourceMappingURL=SidebarSubMenuNext.uni.driver.js.map