"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.tabsUniDriverFactory = void 0;
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
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 tabsUniDriverFactory = base => {
  var findFirst = query => {
    return base.$$(query).at(0);
  };
  var itemsContainer = findFirst('div[role="tablist"]');
  var items = itemsContainer.$$('button[role="tab"]');
  var getItemsContainerType = () => {
    return itemsContainer.attr('data-type');
  };
  return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base)), {}, {
    /**
     * Gets all titles text
     * @return {Promise<string[]>}
     */
    getTitles: function () {
      var _getTitles = (0, _asyncToGenerator2.default)(function* () {
        return yield items.map(item => item.text());
      });
      function getTitles() {
        return _getTitles.apply(this, arguments);
      }
      return getTitles;
    }(),
    /**
     * Clicks the tab at index
     * @param {number} index
     * @return {Promise<void>}
     */
    clickTabAt: index => items.at(index).click(),
    /**
     * Gets active tab index
     * @return {Promise<number>}
     */
    getActiveTabIndex: function () {
      var _getActiveTabIndex = (0, _asyncToGenerator2.default)(function* () {
        var itemsDataActive = yield items.map(item => item.attr('data-active'));
        return itemsDataActive.findIndex(active => active === 'true');
      });
      function getActiveTabIndex() {
        return _getActiveTabIndex.apply(this, arguments);
      }
      return getActiveTabIndex;
    }(),
    /**
     * Checks whether tabs type is default
     * @return {Promise<boolean>}
     */
    isDefaultType: function () {
      var _isDefaultType = (0, _asyncToGenerator2.default)(function* () {
        return !(yield getItemsContainerType());
      });
      function isDefaultType() {
        return _isDefaultType.apply(this, arguments);
      }
      return isDefaultType;
    }(),
    /**
     * Gets tabs container type
     * @return {Promise<string>}
     */
    getItemsContainerType,
    /**
     * Gets the data-hook
     * @param {number} index
     * @return {Promise<string>}
     */
    getDataHook: index => items.at(index).attr('data-hook'),
    /**
     * Gets a set of tabs widths
     * @return {Promise<Set<string>>}
     */
    getItemsWidth: function () {
      var _getItemsWidth = (0, _asyncToGenerator2.default)(function* () {
        var itemsWidthArray = yield items.map(/*#__PURE__*/function () {
          var _ref = (0, _asyncToGenerator2.default)(function* (item) {
            var style = yield item.prop('style');
            return style.width;
          });
          return function (_x) {
            return _ref.apply(this, arguments);
          };
        }());
        return new Set(itemsWidthArray);
      });
      function getItemsWidth() {
        return _getItemsWidth.apply(this, arguments);
      }
      return getItemsWidth;
    }(),
    /**
     * Checks whether tabs has a divider
     * @return {Promise<boolean>}
     */
    hasDivider: function () {
      var _hasDivider = (0, _asyncToGenerator2.default)(function* () {
        return (yield base.attr('data-divider')) === 'true';
      });
      function hasDivider() {
        return _hasDivider.apply(this, arguments);
      }
      return hasDivider;
    }(),
    /**
     * Gets the side content
     * @return {UniDriver}
     */
    sideContent: findFirst("[data-content=\"true\"]"),
    /**
     * @deprecated use sideContent
     * @return {Promise<UniDriver>}
     */
    getSideContent: function () {
      var _getSideContent = (0, _asyncToGenerator2.default)(function* () {
        return findFirst("[data-content=\"true\"]");
      });
      function getSideContent() {
        return _getSideContent.apply(this, arguments);
      }
      return getSideContent;
    }(),
    /**
     * Gets tabs max widths
     * @return {Promise<string[]>}
     */
    getItemsMaxWidths: function () {
      var _getItemsMaxWidths = (0, _asyncToGenerator2.default)(function* () {
        return yield items.map(/*#__PURE__*/function () {
          var _ref2 = (0, _asyncToGenerator2.default)(function* (item) {
            var style = yield item.prop('style');
            return style.maxWidth;
          });
          return function (_x2) {
            return _ref2.apply(this, arguments);
          };
        }());
      });
      function getItemsMaxWidths() {
        return _getItemsMaxWidths.apply(this, arguments);
      }
      return getItemsMaxWidths;
    }(),
    /**
     * Gets tabs min widths
     * @return {Promise<string[]>}
     */
    getItemsMinWidths: function () {
      var _getItemsMinWidths = (0, _asyncToGenerator2.default)(function* () {
        return yield items.map(/*#__PURE__*/function () {
          var _ref3 = (0, _asyncToGenerator2.default)(function* (item) {
            var style = yield item.prop('style');
            return style.minWidth;
          });
          return function (_x3) {
            return _ref3.apply(this, arguments);
          };
        }());
      });
      function getItemsMinWidths() {
        return _getItemsMinWidths.apply(this, arguments);
      }
      return getItemsMinWidths;
    }()
  });
};
exports.tabsUniDriverFactory = tabsUniDriverFactory;
//# sourceMappingURL=Tabs.uni.driver.js.map