"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.segmentedToggleDriverFactory = void 0;
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var segmentedToggleDriverFactory = base => {
  var findChild = hook => {
    if (typeof hook === 'string') {
      return base.$("[data-hook=\"".concat(hook, "\"]"));
    }
    return base.$("[data-click=\"segmented-toggle-".concat(hook, "\"]"));
  };
  return {
    /**
     * Selects child by given number (selection begins with 1) or dataHook
     * @param {string | number} hook Hook name or index
     * @returns { Promise<void>}
     */
    selectChild: function () {
      var _selectChild = (0, _asyncToGenerator2.default)(function* (hook) {
        return findChild(hook).click();
      });
      function selectChild(_x) {
        return _selectChild.apply(this, arguments);
      }
      return selectChild;
    }(),
    /**
     * Returns true if child is selected by given number (selection begins with 1) or dataHook
     * @param {string | number} hook Hook name or index
     * @returns { Promise<void>}
     */
    isSelected: function () {
      var _isSelected = (0, _asyncToGenerator2.default)(function* (hook) {
        return (yield findChild(hook).attr('aria-checked')) === 'true';
      });
      function isSelected(_x2) {
        return _isSelected.apply(this, arguments);
      }
      return isSelected;
    }(),
    /**
     * Checks whether element is in the DOM
     * @returns { Promise<boolean>}
     */
    exists: function () {
      var _exists = (0, _asyncToGenerator2.default)(function* () {
        return yield base.exists();
      });
      function exists() {
        return _exists.apply(this, arguments);
      }
      return exists;
    }(),
    /**
     * Gets the actual element
     * @returns { Promise<any>}
     */
    element: function () {
      var _element = (0, _asyncToGenerator2.default)(function* () {
        return yield base.getNative();
      });
      function element() {
        return _element.apply(this, arguments);
      }
      return element;
    }(),
    /**
     * Returns the size applied to segmented toggle
     * @returns { Promise<'small' | 'medium'>}
     */
    getSize: function () {
      var _getSize = (0, _asyncToGenerator2.default)(function* () {
        return base.attr('data-size');
      });
      function getSize() {
        return _getSize.apply(this, arguments);
      }
      return getSize;
    }(),
    /**
     * returns if the segmented toggle is disabled
     * @returns { Promise<boolean>}
     */
    isDisabled: function () {
      var _isDisabled = (0, _asyncToGenerator2.default)(function* () {
        return (yield base.$$('button[disabled]').count()) > 0;
      });
      function isDisabled() {
        return _isDisabled.apply(this, arguments);
      }
      return isDisabled;
    }(),
    /**
     * Returns true if child is disabled by given number (selection begins with 1) or dataHook
     * @param {string | number} hook Hook name or index
     * @returns { Promise<boolean>}
     */
    isChildDisabled: function () {
      var _isChildDisabled = (0, _asyncToGenerator2.default)(function* (hook) {
        return (yield findChild(hook).attr('disabled')) !== null;
      });
      function isChildDisabled(_x3) {
        return _isChildDisabled.apply(this, arguments);
      }
      return isChildDisabled;
    }()
  };
};
exports.segmentedToggleDriverFactory = segmentedToggleDriverFactory;
//# sourceMappingURL=SegmentedToggle.uni.driver.js.map