"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.popoverNextUniDriverFactory = 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");
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 popoverNextUniDriverFactory = (base, body) => {
  var byHook = hook => base.$("[data-hook=\"".concat(hook, "\"]"));
  var getRoot = /*#__PURE__*/function () {
    var _ref = (0, _asyncToGenerator2.default)(function* () {
      var isBaseRoot = !!(yield base.attr('data-popover-root'));
      return isBaseRoot ? base : base.$('[data-popover-root]');
    });
    return function getRoot() {
      return _ref.apply(this, arguments);
    };
  }();
  var getRootDataHook = /*#__PURE__*/function () {
    var _ref2 = (0, _asyncToGenerator2.default)(function* () {
      var _yield$yield$getRoot$;
      return (_yield$yield$getRoot$ = yield (yield getRoot()).attr('data-hook')) !== null && _yield$yield$getRoot$ !== void 0 ? _yield$yield$getRoot$ : undefined;
    });
    return function getRootDataHook() {
      return _ref2.apply(this, arguments);
    };
  }();
  var getTrigger = /*#__PURE__*/function () {
    var _ref3 = (0, _asyncToGenerator2.default)(function* () {
      var dataHook = yield getRootDataHook();
      return (0, _unidriver.getByHook)(body, "".concat(dataHook, "-trigger"));
    });
    return function getTrigger() {
      return _ref3.apply(this, arguments);
    };
  }();
  var getContent = /*#__PURE__*/function () {
    var _ref4 = (0, _asyncToGenerator2.default)(function* () {
      var dataHook = yield getRootDataHook();
      var content;
      try {
        content = yield (0, _unidriver.getByHook)(body, "".concat(dataHook, "-content"));
      } catch (e) {}
      return content;
    });
    return function getContent() {
      return _ref4.apply(this, arguments);
    };
  }();
  var getTriggerElement = /*#__PURE__*/function () {
    var _ref5 = (0, _asyncToGenerator2.default)(function* () {
      return (yield getTrigger()).getNative();
    });
    return function getTriggerElement() {
      return _ref5.apply(this, arguments);
    };
  }();
  var triggerExists = /*#__PURE__*/function () {
    var _ref6 = (0, _asyncToGenerator2.default)(function* () {
      try {
        var trigger = yield getTrigger();
        return trigger.exists();
      } catch (_unused) {
        return false;
      }
    });
    return function triggerExists() {
      return _ref6.apply(this, arguments);
    };
  }();
  var getContentElement = /*#__PURE__*/function () {
    var _ref7 = (0, _asyncToGenerator2.default)(function* () {
      var _yield$getContent;
      return (_yield$getContent = yield getContent()) == null ? void 0 : _yield$getContent.getNative();
    });
    return function getContentElement() {
      return _ref7.apply(this, arguments);
    };
  }();
  return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base)), {}, {
    /**
     * Clicks the trigger element
     * @returns {Promise<void>}
     */
    click: function () {
      var _click = (0, _asyncToGenerator2.default)(function* () {
        try {
          var trigger = yield getTrigger();
          return trigger.click();
        } catch (_unused2) {}
      });
      function click() {
        return _click.apply(this, arguments);
      }
      return click;
    }(),
    /**
     * Gets the trigger element
     * @returns {Promise<any>}
     */
    getTriggerElement,
    /**
     * Gets the target element
     * @deprecated use getTriggerElement
     * @returns {Promise<any>}
     */
    getTargetElement: getTriggerElement,
    /**
     * Checks whether the trigger element exists
     * @returns {Promise<boolean>}
     */
    triggerExists,
    /**
     * Checks whether target element exists
     * @deprecated use triggerExists
     * @returns {Promise<boolean>}
     */
    isTargetElementExists: triggerExists,
    /**
     * Gets the portal element
     * @deprecated
     * @returns {Promise<any>}
     */
    getPortalElement: function () {
      var _getPortalElement = (0, _asyncToGenerator2.default)(function* () {
        return byHook('popover-portal').getNative();
      });
      function getPortalElement() {
        return _getPortalElement.apply(this, arguments);
      }
      return getPortalElement;
    }(),
    /**
     * Gets the content element
     * @returns {Promise<any>}
     */
    getContentElement,
    /**
     * Checks whether content element exists
     * @returns {Promise<boolean>}
     */
    isContentElementExists: function () {
      var _isContentElementExists = (0, _asyncToGenerator2.default)(function* () {
        var _yield$getContent$exi, _yield$getContent2;
        return (_yield$getContent$exi = (_yield$getContent2 = yield getContent()) == null ? void 0 : _yield$getContent2.exists()) !== null && _yield$getContent$exi !== void 0 ? _yield$getContent$exi : false;
      });
      function isContentElementExists() {
        return _isContentElementExists.apply(this, arguments);
      }
      return isContentElementExists;
    }(),
    /**
     * Triggers a mouseEnter event
     * @returns {Promise<void>}
     */
    mouseEnter: function () {
      var _mouseEnter = (0, _asyncToGenerator2.default)(function* () {
        var trigger = yield getTrigger();
        return trigger.mouse.hover();
      });
      function mouseEnter() {
        return _mouseEnter.apply(this, arguments);
      }
      return mouseEnter;
    }(),
    /**
     * Triggers a mouseLeave event
     * @returns {Promise<void>}
     */
    mouseLeave: function () {
      var _mouseLeave = (0, _asyncToGenerator2.default)(function* () {
        var trigger = yield getTrigger();
        return trigger.mouse.leave();
      });
      function mouseLeave() {
        return _mouseLeave.apply(this, arguments);
      }
      return mouseLeave;
    }(),
    /**
     * Clicks outside the target element
     * @returns {Promise<void>}
     */
    clickOutside: function () {
      var _clickOutside = (0, _asyncToGenerator2.default)(function* () {
        return body.click();
      });
      function clickOutside() {
        return _clickOutside.apply(this, arguments);
      }
      return clickOutside;
    }(),
    /**
     * Gets the arrow offset
     * @returns {Promise<any>}
     */
    getArrowOffset: function () {
      var _getArrowOffset = (0, _asyncToGenerator2.default)(function* () {
        var _yield$byHook$getNati;
        return (_yield$byHook$getNati = yield byHook('popover-arrow').getNative()) == null ? void 0 : _yield$byHook$getNati.style;
      });
      function getArrowOffset() {
        return _getArrowOffset.apply(this, arguments);
      }
      return getArrowOffset;
    }(),
    /**
     * Gets content as unidriver element
     * @deprecated
     * @internal
     * Use `getContent` instead.
     * This is left out for feature parity.
     */
    getContentElementUniDriver: function () {
      var _getContentElementUniDriver = (0, _asyncToGenerator2.default)(function* () {
        return getContent();
      });
      function getContentElementUniDriver() {
        return _getContentElementUniDriver.apply(this, arguments);
      }
      return getContentElementUniDriver;
    }(),
    /**
     * Checks whether the content is visible
     * @returns {Promise<boolean>}
     */
    isContentVisible: function () {
      var _isContentVisible = (0, _asyncToGenerator2.default)(function* () {
        try {
          var content = yield getContent();
          return (yield content == null ? void 0 : content.exists()) === true;
        } catch (_unused3) {
          return false;
        }
      });
      function isContentVisible() {
        return _isContentVisible.apply(this, arguments);
      }
      return isContentVisible;
    }()
  });
};
exports.popoverNextUniDriverFactory = popoverNextUniDriverFactory;
//# sourceMappingURL=PopoverNext.uni.driver.js.map