"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = 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 _testUtils = require("../utils/test-utils");
var _LoaderUni = require("../Loader/Loader.uni.driver");
var _TrendIndicatorUni = require("../TrendIndicator/TrendIndicator.uni.driver");
var _AdaptiveHeadingUni = require("../common/AdaptiveHeading/AdaptiveHeading.uni.driver");
var _InfoIconUni = require("../InfoIcon/InfoIcon.uni.driver");
var _dataHooks = _interopRequireDefault(require("./dataHooks"));
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 statisticsWidgetDriverFactory = (base, body) => {
  var getHookSelector = hook => "[data-hook=\"".concat(hook, "\"]");
  var getStatsItem = /*#__PURE__*/function () {
    var _ref = (0, _asyncToGenerator2.default)(function* (index) {
      return base.$$(getHookSelector(_dataHooks.default.stat)).get(index);
    });
    return function getStatsItem(_x) {
      return _ref.apply(this, arguments);
    };
  }();
  var getInfoIconDriver = /*#__PURE__*/function () {
    var _ref2 = (0, _asyncToGenerator2.default)(function* (index) {
      var item = yield getStatsItem(index);
      var infoIcon = yield item.$(getHookSelector(_dataHooks.default.info));
      return (0, _InfoIconUni.infoIconDriverFactory)(infoIcon, body);
    });
    return function getInfoIconDriver(_x2) {
      return _ref2.apply(this, arguments);
    };
  }();
  var getTrendIndicatorDriver = /*#__PURE__*/function () {
    var _ref3 = (0, _asyncToGenerator2.default)(function* (index) {
      var item = yield getStatsItem(index);
      var tooltip = yield item.$(getHookSelector(_dataHooks.default.percentage));
      return (0, _TrendIndicatorUni.trendIndicatorDriverFactory)(tooltip, body);
    });
    return function getTrendIndicatorDriver(_x3) {
      return _ref3.apply(this, arguments);
    };
  }();
  var getAdaptiveHeadingDriver = /*#__PURE__*/function () {
    var _ref4 = (0, _asyncToGenerator2.default)(function* (index) {
      var item = yield getStatsItem(index);
      var heading = yield item.$(getHookSelector(_dataHooks.default.value));
      return (0, _AdaptiveHeadingUni.adaptiveHeadingDriverFactory)(heading);
    });
    return function getAdaptiveHeadingDriver(_x4) {
      return _ref4.apply(this, arguments);
    };
  }();
  var getLoaderDriver = /*#__PURE__*/function () {
    var _ref5 = (0, _asyncToGenerator2.default)(function* (index) {
      var item = yield getStatsItem(index);
      var loader = yield item.$(getHookSelector(_dataHooks.default.loader));
      return (0, _LoaderUni.loaderUniDriverFactory)(loader);
    });
    return function getLoaderDriver(_x5) {
      return _ref5.apply(this, arguments);
    };
  }();
  var getStatsPartText = /*#__PURE__*/function () {
    var _ref6 = (0, _asyncToGenerator2.default)(function* (index, hook) {
      var node = (0, _testUtils.findBaseByHook)(yield getStatsItem(index), hook);
      if (!(yield node.exists())) {
        return null;
      }
      return yield node.text();
    });
    return function getStatsPartText(_x6, _x7) {
      return _ref6.apply(this, arguments);
    };
  }();
  return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base)), {}, {
    /** Get number of items */
    getItemsCount: function () {
      var _getItemsCount = (0, _asyncToGenerator2.default)(function* () {
        return yield base.$$(getHookSelector(_dataHooks.default.stat)).count();
      });
      function getItemsCount() {
        return _getItemsCount.apply(this, arguments);
      }
      return getItemsCount;
    }(),
    /** Click on the statistic with index */
    clickStatistics: function () {
      var _clickStatistics = (0, _asyncToGenerator2.default)(function* (index) {
        var item = yield getStatsItem(index);
        return item.click();
      });
      function clickStatistics(_x8) {
        return _clickStatistics.apply(this, arguments);
      }
      return clickStatistics;
    }(),
    /** Get value of the statistic with index */
    getValue: function () {
      var _getValue = (0, _asyncToGenerator2.default)(function* (index) {
        var heading = yield getAdaptiveHeadingDriver(index);
        return heading.getText();
      });
      function getValue(_x9) {
        return _getValue.apply(this, arguments);
      }
      return getValue;
    }(),
    /**
     * Returns true if statistic item is in loading state
     * @param index: number
     */
    isLoading: function () {
      var _isLoading = (0, _asyncToGenerator2.default)(function* (index) {
        var loader = yield getLoaderDriver(index);
        return loader.isLoading();
      });
      function isLoading(_x0) {
        return _isLoading.apply(this, arguments);
      }
      return isLoading;
    }(),
    /** Get short value of the stat with index */
    getValueInShort: function () {
      var _getValueInShort = (0, _asyncToGenerator2.default)(function* (index) {
        var heading = yield getAdaptiveHeadingDriver(index);
        return heading.getShortText();
      });
      function getValueInShort(_x1) {
        return _getValueInShort.apply(this, arguments);
      }
      return getValueInShort;
    }(),
    /** Get description of the statistic with index */
    getDescription: function () {
      var _getDescription = (0, _asyncToGenerator2.default)(function* (index) {
        return getStatsPartText(index, _dataHooks.default.description);
      });
      function getDescription(_x10) {
        return _getDescription.apply(this, arguments);
      }
      return getDescription;
    }(),
    /** Get the text of the info tooltip */
    getDescriptionInfo: function () {
      var _getDescriptionInfo = (0, _asyncToGenerator2.default)(function* (index) {
        var infoIconDriver = yield getInfoIconDriver(index);
        if (!(yield infoIconDriver.exists())) {
          return null;
        }
        return infoIconDriver.getContent();
      });
      function getDescriptionInfo(_x11) {
        return _getDescriptionInfo.apply(this, arguments);
      }
      return getDescriptionInfo;
    }(),
    /** Get children in section by hook */
    getChildren: function () {
      var _getChildren = (0, _asyncToGenerator2.default)(function* (index, hook) {
        return (0, _testUtils.findBaseByHook)(yield getStatsItem(index), hook);
      });
      function getChildren(_x12, _x13) {
        return _getChildren.apply(this, arguments);
      }
      return getChildren;
    }(),
    /** Get percentage of the statistic with index */
    getPercentage: function () {
      var _getPercentage = (0, _asyncToGenerator2.default)(function* (index) {
        var trendIndicator = yield getTrendIndicatorDriver(index);
        if (!(yield trendIndicator.exists())) {
          return null;
        }
        return yield trendIndicator.getTrendValue();
      });
      function getPercentage(_x14) {
        return _getPercentage.apply(this, arguments);
      }
      return getPercentage;
    }()
  });
};
var _default = exports.default = statisticsWidgetDriverFactory;
//# sourceMappingURL=StatisticsWidget.uni.driver.js.map