"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.linkingButtonDriver = exports.default = exports.cornerRadiusInputDriverFactory = exports.cornerInputDriver = 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 _CornerRadiusInput = require("./CornerRadiusInput.constants");
var _NumberInputUni = require("../NumberInput/NumberInput.uni.driver");
var _ToggleButtonUni = require("../ToggleButton/ToggleButton.uni.driver");
var _LiveRegionUni = require("../LiveRegion/LiveRegion.uni.driver");
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 linkingButtonDriver = (base, body) => {
  var linkingButtonBase = (0, _unidriver.findByHook)(base, _CornerRadiusInput.dataHooks.autoScaleButton);
  var {
    isButtonSelected,
    click,
    exists,
    element,
    getLabelValue
  } = (0, _ToggleButtonUni.toggleButtonDriverFactory)(linkingButtonBase, body);
  return {
    click,
    exists,
    element,
    isButtonSelected,
    getLabelValue
  };
};
exports.linkingButtonDriver = linkingButtonDriver;
var cornerInputDriver = exports.cornerInputDriver = /*#__PURE__*/function () {
  var _ref = (0, _asyncToGenerator2.default)(function* (corner, base, body) {
    var cornerToHook = {
      topLeft: _CornerRadiusInput.dataHooks.topLeft,
      topRight: _CornerRadiusInput.dataHooks.topRight,
      bottomLeft: _CornerRadiusInput.dataHooks.bottomLeft,
      bottomRight: _CornerRadiusInput.dataHooks.bottomRight
    };
    var inputBase = (0, _unidriver.findByHook)(base, cornerToHook[corner]);
    var {
      enterText,
      getAriaLabel,
      getValue,
      hasStatus,
      getSize,
      getCustomAffixText
    } = (0, _NumberInputUni.numberInputDriverFactory)(inputBase, body);
    return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(inputBase)), {}, {
      /** Checks if input has provided status */
      hasStatus,
      /** Focuses input element */
      enterText,
      /** Returns aria label  */
      getAriaLabel,
      /** Returns input value  */
      getValue,
      /** Returns if the element is currently focused */
      getSize,
      /** Returns the suffix text */
      getSuffixText: getCustomAffixText
    });
  });
  return function cornerInputDriver(_x, _x2, _x3) {
    return _ref.apply(this, arguments);
  };
}();
var cornerRadiusInputDriverFactory = (base, body) => {
  var linkingButton = linkingButtonDriver(base, body);
  return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base)), {}, {
    /** returns if linking functionality is enabled */
    isLinked: function () {
      var _isLinked = (0, _asyncToGenerator2.default)(function* () {
        return linkingButton.isButtonSelected();
      });
      function isLinked() {
        return _isLinked.apply(this, arguments);
      }
      return isLinked;
    }(),
    /** returns the size of component */
    getSize: function () {
      var _getSize = (0, _asyncToGenerator2.default)(function* () {
        // same size applied to all corners
        var topLeft = yield cornerInputDriver('topLeft', base, body);
        return topLeft.getSize();
      });
      function getSize() {
        return _getSize.apply(this, arguments);
      }
      return getSize;
    }(),
    /**
     * Returns the testkit of the input of the specified corner
     */
    getCornerInput: function () {
      var _getCornerInput = (0, _asyncToGenerator2.default)(function* (corner) {
        return cornerInputDriver(corner, base, body);
      });
      function getCornerInput(_x4) {
        return _getCornerInput.apply(this, arguments);
      }
      return getCornerInput;
    }(),
    /** Returns linking button testkit */
    linkingButton,
    /** @deprecated use linkingButton */
    getLinkingButton: function () {
      var _getLinkingButton = (0, _asyncToGenerator2.default)(function* () {
        return linkingButton;
      });
      function getLinkingButton() {
        return _getLinkingButton.apply(this, arguments);
      }
      return getLinkingButton;
    }(),
    getLinkedValuesChangedMessage: function () {
      var _getLinkedValuesChangedMessage = (0, _asyncToGenerator2.default)(function* () {
        var {
          getMessage
        } = (0, _LiveRegionUni.liveRegionDriverFactory)((0, _unidriver.findByHook)(base, _CornerRadiusInput.dataHooks.liveRegion));
        return getMessage();
      });
      function getLinkedValuesChangedMessage() {
        return _getLinkedValuesChangedMessage.apply(this, arguments);
      }
      return getLinkedValuesChangedMessage;
    }()
  });
};
exports.cornerRadiusInputDriverFactory = cornerRadiusInputDriverFactory;
var _default = exports.default = cornerRadiusInputDriverFactory;
//# sourceMappingURL=CornerRadiusInput.uni.driver.js.map