"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.formFieldUniDriverFactory = 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 _InfoIconUni = require("../InfoIcon/InfoIcon.uni.driver");
var _TextUni = require("../Text/Text.uni.driver");
var _FormField = require("./FormField.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 formFieldUniDriverFactory = (base, body) => {
  var charactersCounter = () => base.$("[data-hook*=\"".concat(_FormField.DATA_HOOKS.counter, "\"]"));
  return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base)), {}, {
    element: function () {
      var _element = (0, _asyncToGenerator2.default)(function* () {
        return (0, _unidriver.baseUniDriverFactory)(base).element();
      });
      function element() {
        return _element.apply(this, arguments);
      }
      return element;
    }(),
    /** get children */
    getChildren: function () {
      var _getChildren = (0, _asyncToGenerator2.default)(function* () {
        var baseUniDriverElement = base.$("[data-hook*=\"".concat(_FormField.DATA_HOOKS.children, "\"]"));
        return (yield baseUniDriverElement.exists()) ? baseUniDriverElement.getNative() : null;
      });
      function getChildren() {
        return _getChildren.apply(this, arguments);
      }
      return getChildren;
    }(),
    /** get label */
    getLabel: function () {
      var _getLabel = (0, _asyncToGenerator2.default)(function* () {
        var baseUniDriverElement = base.$("[data-hook*=\"".concat(_FormField.DATA_HOOKS.label, "\"]"));
        return (yield baseUniDriverElement.exists()) ? baseUniDriverElement.getNative() : null;
      });
      function getLabel() {
        return _getLabel.apply(this, arguments);
      }
      return getLabel;
    }(),
    /** returns label size */
    getLabelSize: function () {
      var _getLabelSize = (0, _asyncToGenerator2.default)(function* () {
        var labelDriver = (0, _TextUni.textUniDriverFactory)(base.$("[data-hook=\"".concat(_FormField.DATA_HOOKS.label, "\"]")));
        return labelDriver.getSize();
      });
      function getLabelSize() {
        return _getLabelSize.apply(this, arguments);
      }
      return getLabelSize;
    }(),
    /** returns true whether form field is required */
    isRequired: function () {
      var _isRequired = (0, _asyncToGenerator2.default)(function* () {
        return base.$("[data-hook*=\"".concat(_FormField.DATA_HOOKS.asterisk, "\"]")).exists();
      });
      function isRequired() {
        return _isRequired.apply(this, arguments);
      }
      return isRequired;
    }(),
    /** returns the length left */
    getLengthLeft: function () {
      var _getLengthLeft = (0, _asyncToGenerator2.default)(function* () {
        var counter = charactersCounter();
        return (yield counter.exists()) ? parseInt(yield counter.prop('innerHTML'), 10) : null;
      });
      function getLengthLeft() {
        return _getLengthLeft.apply(this, arguments);
      }
      return getLengthLeft;
    }(),
    /** returns whether the form field length is exceeded */
    isLengthExceeded: function () {
      var _isLengthExceeded = (0, _asyncToGenerator2.default)(function* () {
        var counter = charactersCounter();
        if (yield counter.exists()) {
          var length = parseInt(yield counter.prop('innerHTML'), 10);
          return length < 0;
        }
        return false;
      });
      function isLengthExceeded() {
        return _isLengthExceeded.apply(this, arguments);
      }
      return isLengthExceeded;
    }(),
    /** returns true whether form field has tooltip */
    hasTooltip: function () {
      var _hasTooltip = (0, _asyncToGenerator2.default)(function* () {
        return base.$("[data-hook=\"".concat(_FormField.DATA_HOOKS.infoIcon, "\"]")).exists();
      });
      function hasTooltip() {
        return _hasTooltip.apply(this, arguments);
      }
      return hasTooltip;
    }(),
    /** returns tooltip text of the info content */
    getInfoContent: function () {
      var _getInfoContent = (0, _asyncToGenerator2.default)(function* () {
        var testkit = (0, _InfoIconUni.infoIconDriverFactory)(base.$("[data-hook=\"".concat(_FormField.DATA_HOOKS.infoIcon, "\"]")), body);
        return testkit.getContent();
      });
      function getInfoContent() {
        return _getInfoContent.apply(this, arguments);
      }
      return getInfoContent;
    }(),
    /** get form field suffix */
    getSuffix: function () {
      var _getSuffix = (0, _asyncToGenerator2.default)(function* () {
        var suffixElement = base.$("[data-hook=\"".concat(_FormField.DATA_HOOKS.suffix, "\"]"));
        return (yield suffixElement.exists()) ? suffixElement.getNative() : null;
      });
      function getSuffix() {
        return _getSuffix.apply(this, arguments);
      }
      return getSuffix;
    }(),
    /** hovers over the formfield infoicon */
    hoverInfoIcon: function () {
      var _hoverInfoIcon = (0, _asyncToGenerator2.default)(function* () {
        var testkit = (0, _InfoIconUni.infoIconDriverFactory)(base.$("[data-hook=\"".concat(_FormField.DATA_HOOKS.infoIcon, "\"]")), body);
        return testkit.hover();
      });
      function hoverInfoIcon() {
        return _hoverInfoIcon.apply(this, arguments);
      }
      return hoverInfoIcon;
    }(),
    /** returns status message text */
    getStatusMessage: function () {
      var _getStatusMessage = (0, _asyncToGenerator2.default)(function* () {
        var testkit = (0, _TextUni.textUniDriverFactory)(base.$("[data-hook=\"".concat(_FormField.DATA_HOOKS.statusMessage, "\"]")));
        return testkit.getText();
      });
      function getStatusMessage() {
        return _getStatusMessage.apply(this, arguments);
      }
      return getStatusMessage;
    }(),
    /** return true if it has a given status */
    hasStatus: function () {
      var _hasStatus = (0, _asyncToGenerator2.default)(function* (status) {
        return (yield base.attr('data-status')) === status;
      });
      function hasStatus(_x) {
        return _hasStatus.apply(this, arguments);
      }
      return hasStatus;
    }()
  });
};
exports.formFieldUniDriverFactory = formFieldUniDriverFactory;
//# sourceMappingURL=FormField.uni.driver.js.map