"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.inputAreaUniDriverFactory = 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");
var _StatusIndicatorUni = require("../StatusIndicator/StatusIndicator.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 inputAreaUniDriverFactory = (base, body) => {
  var textArea = base.$('textarea');
  var counterSelector = '[data-hook="counter"]';
  var getStatusIndicatorDriver = () => (0, _StatusIndicatorUni.statusIndicatorDriverFactory)(base.$("[data-hook=\"".concat(_constants.dataHooks.tooltip, "\"]")), body);
  var textAreaBase = (0, _unidriver.ReactBase)(textArea);
  return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base)), {}, {
    trigger: (_trigger, event) => textAreaBase[_trigger](event),
    focus: () => textAreaBase.focus(),
    enterText: text => textArea.enterValue(text),
    getValue: () => textArea.value(),
    getName: () => textArea.attr('name'),
    getPlaceholder: () => textArea.prop('placeholder'),
    getDefaultValue: () => textArea.prop('defaultValue'),
    getRowsCount: () => textArea.prop('rows'),
    getMaxLength: () => textArea.prop('maxLength'),
    getMinLength: () => textArea.prop('minLength'),
    getTabIndex: () => textArea.prop('tabIndex'),
    getReadOnly: () => textArea.prop('readOnly'),
    getCursorLocation: () => textArea.prop('selectionStart'),
    getResizable: function () {
      var _getResizable = (0, _asyncToGenerator2.default)(function* () {
        return !!(yield base.attr(_constants.dataAttr.RESIZABLE));
      });
      function getResizable() {
        return _getResizable.apply(this, arguments);
      }
      return getResizable;
    }(),
    getDisabled: function () {
      var _getDisabled = (0, _asyncToGenerator2.default)(function* () {
        return !!(yield base.attr(_constants.dataAttr.DISABLED)) && !!(yield textArea.prop('disabled'));
      });
      function getDisabled() {
        return _getDisabled.apply(this, arguments);
      }
      return getDisabled;
    }(),
    getRequired: () => textArea.prop('required'),
    getHasCounter: function () {
      var _getHasCounter = (0, _asyncToGenerator2.default)(function* () {
        return (yield base.$$(counterSelector).count()) > 0;
      });
      function getHasCounter() {
        return _getHasCounter.apply(this, arguments);
      }
      return getHasCounter;
    }(),
    getCounterValue: () => base.$(counterSelector).text(),
    hasExclamation: () => getStatusIndicatorDriver().exists(),
    isFocusedStyle: function () {
      var _isFocusedStyle = (0, _asyncToGenerator2.default)(function* () {
        return !!(yield base.attr(_constants.dataAttr.FOCUS));
      });
      function isFocusedStyle() {
        return _isFocusedStyle.apply(this, arguments);
      }
      return isFocusedStyle;
    }(),
    isSizeSmall: function () {
      var _isSizeSmall = (0, _asyncToGenerator2.default)(function* () {
        return (yield base.attr(_constants.dataAttr.SIZE)) === 'small';
      });
      function isSizeSmall() {
        return _isSizeSmall.apply(this, arguments);
      }
      return isSizeSmall;
    }(),
    isHoveredStyle: function () {
      var _isHoveredStyle = (0, _asyncToGenerator2.default)(function* () {
        return !!(yield base.attr(_constants.dataAttr.HOVER));
      });
      function isHoveredStyle() {
        return _isHoveredStyle.apply(this, arguments);
      }
      return isHoveredStyle;
    }(),
    isFocus: () => textAreaBase.isFocus(),
    exists: () => textArea.exists(),
    getStyle: () => textArea.prop('style'),
    getAriaLabel: () => textArea.attr('aria-label'),
    getAriaControls: () => textArea.attr('aria-controls'),
    getAriaDescribedby: () => textArea.attr('aria-describedby'),
    getTooltipDataHook: () => _constants.dataHooks.tooltip,
    getTooltipElement: () => base,
    // Status
    /** Return true if there's a status */
    hasStatus: function () {
      var _hasStatus = (0, _asyncToGenerator2.default)(function* (status) {
        var statusIndicatorDriver = getStatusIndicatorDriver();
        if (yield statusIndicatorDriver.exists()) {
          return (yield base.attr(_constants.dataAttr.STATUS)) === status && (yield statusIndicatorDriver.getStatus()) === status;
        }
        return (yield base.attr(_constants.dataAttr.STATUS)) === status;
      });
      function hasStatus(_x) {
        return _hasStatus.apply(this, arguments);
      }
      return hasStatus;
    }(),
    /** If there's a status message, returns its text value */
    getStatusMessage: function () {
      var _getStatusMessage = (0, _asyncToGenerator2.default)(function* () {
        var statusIndicatorDriver = getStatusIndicatorDriver();
        var tooltipText = null;
        if (yield statusIndicatorDriver.hasMessage()) {
          tooltipText = yield statusIndicatorDriver.getMessage();
        }
        return tooltipText;
      });
      function getStatusMessage() {
        return _getStatusMessage.apply(this, arguments);
      }
      return getStatusMessage;
    }()
  });
};
exports.inputAreaUniDriverFactory = inputAreaUniDriverFactory;
//# sourceMappingURL=InputArea.uni.driver.js.map