"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.funnelChartDriverFactory = 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 _TooltipUni = require("../Tooltip/Tooltip.uni.driver");
var _TextUni = require("../Text/Text.uni.driver");
var _constants = require("./constants");
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 funnelChartDriverFactory = (base, body) => {
  var getTooltipDriverAtIndex = /*#__PURE__*/function () {
    var _ref = (0, _asyncToGenerator2.default)(function* (dataHook, index) {
      var tooltip = yield (0, _unidriver.findByHookAtIndex)(base, dataHook, index);
      return (0, _TooltipUni.tooltipDriverFactory)(tooltip, body);
    });
    return function getTooltipDriverAtIndex(_x, _x2) {
      return _ref.apply(this, arguments);
    };
  }();
  var getTextDriverAtIndex = /*#__PURE__*/function () {
    var _ref2 = (0, _asyncToGenerator2.default)(function* (dataHook, index) {
      var text = yield (0, _unidriver.findByHookAtIndex)(base, dataHook, index);
      return (0, _TextUni.textUniDriverFactory)(text, body);
    });
    return function getTextDriverAtIndex(_x3, _x4) {
      return _ref2.apply(this, arguments);
    };
  }();
  return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base, body)), {}, {
    /**
     * Gets number of items
     * @return {Promise<number>}
     */
    getItemsCount: () => (0, _unidriver.countByHook)(base, _constants.dataHooks.funnelChartItem),
    /**
     * Gets item displayed value (after compaction) at index
     * @param {number} index Item index
     * @return {Promise<string>}
     */
    getValueAt: function () {
      var _getValueAt = (0, _asyncToGenerator2.default)(function* (index) {
        return (yield getTextDriverAtIndex(_constants.dataHooks.labelValue, index)).getText();
      });
      function getValueAt(_x5) {
        return _getValueAt.apply(this, arguments);
      }
      return getValueAt;
    }(),
    /**
     * Gets item label at index
     * @param {number} index Item index
     * @return {Promise<string>}
     */
    getLabelAt: function () {
      var _getLabelAt = (0, _asyncToGenerator2.default)(function* (index) {
        return (yield getTextDriverAtIndex(_constants.dataHooks.labelText, index)).getText();
      });
      function getLabelAt(_x6) {
        return _getLabelAt.apply(this, arguments);
      }
      return getLabelAt;
    }(),
    /**
     * Gets badge value from index
     * @param {number} index Item index
     * @return {Promise<string>}
     */
    getDifferenceFromDataAt: function () {
      var _getDifferenceFromDataAt = (0, _asyncToGenerator2.default)(function* (index) {
        var text = yield getTextDriverAtIndex(_constants.dataHooks.badgeValue, index);
        if (!(yield text.exists())) {
          return null;
        }
        return text.getText();
      });
      function getDifferenceFromDataAt(_x7) {
        return _getDifferenceFromDataAt.apply(this, arguments);
      }
      return getDifferenceFromDataAt;
    }(),
    /**
     * Gets badge tooltip from index
     * @param {number} index Item index
     * @return {Promise<string>}
     */
    getDifferenceTooltipFromDataAt: function () {
      var _getDifferenceTooltipFromDataAt = (0, _asyncToGenerator2.default)(function* (index) {
        var tooltip = yield getTooltipDriverAtIndex(_constants.dataHooks.badgeTooltip, index);
        if (!(yield tooltip.exists())) {
          return null;
        }
        return tooltip.getTooltipText();
      });
      function getDifferenceTooltipFromDataAt(_x8) {
        return _getDifferenceTooltipFromDataAt.apply(this, arguments);
      }
      return getDifferenceTooltipFromDataAt;
    }(),
    /**
     * Returns true if badges are displayed
     * @return {Promise<boolean>}
     */
    isDisplayingBadges: function () {
      var _isDisplayingBadges = (0, _asyncToGenerator2.default)(function* () {
        return base.$$("[data-hook=\"".concat(_constants.dataHooks.badge, "\"]")).count() > 0;
      });
      function isDisplayingBadges() {
        return _isDisplayingBadges.apply(this, arguments);
      }
      return isDisplayingBadges;
    }(),
    /**
     * Get tooltip size from index
     * @param {number} index Item index
     * @return {Promise<string>}
     */
    getDifferenceTooltipSizeAt: function () {
      var _getDifferenceTooltipSizeAt = (0, _asyncToGenerator2.default)(function* (index) {
        var tooltip = yield getTooltipDriverAtIndex(_constants.dataHooks.badgeTooltip, index);
        if (!(yield tooltip.exists())) {
          return null;
        }
        return (yield tooltip.element()).getAttribute('data-size');
      });
      function getDifferenceTooltipSizeAt(_x9) {
        return _getDifferenceTooltipSizeAt.apply(this, arguments);
      }
      return getDifferenceTooltipSizeAt;
    }(),
    /**
     * Get step skin from index
     * @param {number} index Item index
     * @return {Promise<string>}
     */
    getDifferenceStepSkinAt: function () {
      var _getDifferenceStepSkinAt = (0, _asyncToGenerator2.default)(function* (index) {
        var step = yield (0, _unidriver.findByHookAtIndex)(base, _constants.dataHooks.step, index);
        if (!(yield step.exists())) {
          return null;
        }
        return step.attr('data-skin');
      });
      function getDifferenceStepSkinAt(_x0) {
        return _getDifferenceStepSkinAt.apply(this, arguments);
      }
      return getDifferenceStepSkinAt;
    }(),
    /**
     * Get badge skin from index
     * @param {number} index Item index
     * @return {Promise<string>}
     */
    getDifferenceBadgeSkinAt: function () {
      var _getDifferenceBadgeSkinAt = (0, _asyncToGenerator2.default)(function* (index) {
        var badge = yield (0, _unidriver.findByHookAtIndex)(base, _constants.dataHooks.badge, index);
        if (!(yield badge.exists())) {
          return null;
        }
        return badge.attr('data-skin');
      });
      function getDifferenceBadgeSkinAt(_x1) {
        return _getDifferenceBadgeSkinAt.apply(this, arguments);
      }
      return getDifferenceBadgeSkinAt;
    }(),
    /**
     * Checks whether badge from index has an icon
     * @param {number} index Item index
     * @return {Promise<boolean>}
     */
    differenceBadgeHasIconAt: function () {
      var _differenceBadgeHasIconAt = (0, _asyncToGenerator2.default)(function* (index) {
        var badge = yield (0, _unidriver.findByHookAtIndex)(base, _constants.dataHooks.badge, index);
        if (!(yield badge.exists())) {
          return null;
        }
        return badge.$('[data-prefix-icon]').exists();
      });
      function differenceBadgeHasIconAt(_x10) {
        return _differenceBadgeHasIconAt.apply(this, arguments);
      }
      return differenceBadgeHasIconAt;
    }()
  });
};
exports.funnelChartDriverFactory = funnelChartDriverFactory;
//# sourceMappingURL=FunnelChart.uni.driver.js.map